Sign in to follow this  
MDI

SRGP / g++ problem.

Recommended Posts

Hi, I'm using SRGP for a class project on Linux. using g++ (GCC) 4.1.1 20060525 (Red Hat 4.1.1-1). Whenever I try to include the SRGP header into my source file, I get the following strange error: /usr/include/unistd.h:418: error: expected primary-expression before ‘__useconds’ /usr/include/unistd.h:418: error: expected `)' before ‘__useconds’ I'm compiling my project with the command: g++ -fpcc-struct-return -I/usr/include/srgp -O2 *.cpp -L/usr/X11R6/lib -lsrgp -lX11 -lm -o cg Whenever I remove the #include <srgp.h> command, the error goes away and the project compiles fine. Has anyone ever had this problem (I'm working on a FC5 machine, if that matters)? The relevant source file is only small. I've tried it with and without the extern "C", aswell as changing the order of the stdio and stdlib includes (the example my lecturer gave of using SRGP had those included):
// FIXME: weird bug here, unistd.h
#include <stdio.h>
#include <stdlib.h>

extern "C" { 
	#include <srgp.h>
}

#include "Window.h"
#include "Canvas.h"

namespace ComputerGraphics
{
	Window::Window()
	{
	}

	// Create a new window and return a canvas for painting onto it.
	ICanvas* Window::create(const std::string& title,
							int width, int height)
	{
		SRGP_begin(const_cast<char*>(title.c_str()), width, height, 8, 1);
		return new Canvas(width, height, WHITE);
	}

	// Destroy the window.
	void Window::destroy(ICanvas* canvas)
	{
		delete canvas;
		canvas = 0;
		SRGP_end();
	}
}

Thanks, MDI.

Share this post


Link to post
Share on other sites
Nevermind, I found the problem. My class declarations have to be included before srgp.h, for some reason.

Share this post


Link to post
Share on other sites
The symptom you describe has all the hallmarks of a C-preprocessor MACRO problem.

A quick glance at <unistd.h> shows that there's probably a macro with the name "usleep" (although it could be "ualarm" or "__useconds_t") somewhere. Alternatively, there could be a header file with the name "stddef.h" somewhere hiding the system header <stddef.h>.

Given that <unistd.h>, <stdio.h>, and <stdlib.h> all come from the same source (in your case, glibc), the problem is either in <sgrp.h> or in your code. A quick check of the preprocessed files (add the -save-temps arg to the gcc command line) and a recursive grep of the SRGP and your project headers might reveal the true cause.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this