-   Programming (
-   -   compile error srgp library in C (

csst0136 10-23-2005 02:48 PM

compile error srgp library in C
i compile the program:

#include <stdio.h>
#include "srgp.h"

int main()
SRGP_begin("hw", 500, 300, 1, TRUE);
return 1;

and i get

/tmp/cc4ddcut.o(text+0x27):In function 'main':
:undefined reference to 'SRGP_begin'

/tmp/cc4ddcut.o(text+0x2f):In function 'main':
:undefined reference to 'SRGP_end'
collect 2:ld returned 1 exit status

Hko 10-24-2005 11:25 AM

You didn't link the lib that contains
SRGP_begin and SRGP_end on the compiler command line.

Or you didn't mention srgp.c after the -o option on the compiler command line.

csst0136 10-24-2005 11:43 AM

how do i link the libraries?there is a file libsrgp.a which contains files with extension .o.I have put libsrgp.a into /usr/lib

i compile the program like :
gcc name_program.c
i dont use -o

deiussum 10-24-2005 12:18 PM

To link libraries, you add -l<libraryname> to your comand line. Library name is the name of a library that is usually in the form lib<libraryname>.so (or .a). So in your case, try using -lsrgp. You may also have to include -static to link static libraries (which is what a .a is), but I don't remember for sure.

csst0136 10-24-2005 03:04 PM

i linked -lsrgp and i get more errors like the others
undefined reference ****

deiussum 10-24-2005 03:13 PM

That's probably because srgp relies on additional libraries. Without seeing exact errors, we can't tell you what additional libraries you need to link, but one trick you can use to find out is to use grep.

For instance, say it is complaining about an undefined reference to xxxxxxx.

Type the following to see if there is a .so file in /usr/lib that has that function.

grep "xxxxxxx" /usr/lib/*.so

(Note: This sometimes find files that rely on that function as well, so it doesn't necessarily mean that the function is exported from all the .so files it finds...)

Now, assuming it found a reference xxxxxxx in, you could then try adding -lyyyyy.

Edit: You may also have to look in other library directories such as /usr/X11R6/lib. If you find a library you need in any directory that is not part of the standard library search path, you can add it to the search path by adding -L/path/to/library to your command line. Using my previous example, if you found that /usr/X11R6/lib/ had what you needed you would add:

-L/usr/X11R6/lib -lyyyyy

paulsm4 10-24-2005 04:07 PM

Hi -

As I mentioned in a separate post: please e-mail me the link where you downloaded your version of srgp, and I'll try test building it myself and let you know what I find.

There's every chance it's a simple syntax error in your "makefile", or something not configured correctly in your environment.

On the other hand, it's also possible that this library isn't even intended for Linux, and it might be more trouble that it's worth trying to get it to compile and link.

Please let me know.

Your .. PSM

csst0136 10-24-2005 04:17 PM

i run command grep and i found some libraries like

i linked just one of them for example libplot and i didnt get errors but when i run it with ./a.out i got

SRGP:Color table too full to share
A solution is to have the SRGP application request
0 planes in the 4th parameter to SRGP_begin.
For now, the application will have its own
color table rather than try to share.

(examining the core will be usefull only if using X in synchronous mode):
Badmatch (invalid parameter attributes)

If your application is an SRGP application ,please remember:
if the error message above says
that you sent a bad argument to a certain function,
you should run your program with tracing ON in order
to see exactly what you sent
If you already had tracing enabled,remember to look in
'SRGPlogfile' for the tracing messages

deiussum 10-24-2005 04:22 PM

He posted the location in his other duplicate thread as,

I took a quick look myself, and the examples makefile there also links in -lX11. My guess is that though this is an old library, it should work in Linux.

So, try add ing -L/usr/X11R6/lib -lX1ll.

If it still doesn't work, post the exact undefined references and/or try to find the appropriate library with grep.

Give a man a fish, he eats for a day. Teach a man to fish, he eats for a lifetime...

deiussum 10-24-2005 04:31 PM

Ok, looks like you got it to compile while I was posting my last response. You can find the SRGP docs at

It says this about that fourth parameter of SRGP_begin:


The fourth parameter is meaningful only on a display supporting color. It specifies how many planes of the color table should be reserved for SRGP's use; i.e., it places an upper bound on the number of colors that may be displayed simultaneously in the SRGP window. (The upper bound is colors, where is the number of planes.) The fourth parameter is ignored when the program is run on a bilevel display.

If the program is being run on a color display, and you send the special value "0" as the fourth parameter, SRGP will take over the entire color table, giving your application color support as rich as the hardware can offer. (After initializing SRGP, you can inquire the "canvas depth" to determine how many planes are available.) The disadvantage: it will be impossible for the user to simultaneously see the SRGP window's proper coloring and the other clients' windows' proper coloring. Thus, you should request "0" planes only when your application truly needs full control of the color table.
Are you running this from X? I might try passing 0 there to see what happens. Passing 1 sounds like you are requesting only 1 color. It does say it ignores it on a "bilevel display," but I'm not exactly sure what it means by that. I don't think I've ever heard that term used before, but my guess would be it means some sort of GUI system like X11...

paulsm4 10-24-2005 05:05 PM

Thank you very much, deiussum.

I'm exiting stage left for now. The main points that I found (posted in csst0136's other thread) are:

1. srgp.tar.Z extracts nicely into its own subdirectory. You don't need to copy anything into other
places (and certainly not into /usr/lib).

2. You can build the examples with the syntax:

make PROG=xxx (e.g. "make PROG=testpaint", from the "SRGP_DISTRIB/examples" subdirectory)

3. Before you do this, however, you must rebuild "libsrgp.a" (it does not appear to be a Linux/ELF archive)

4. You must add "-I../include", "-L../lib" (both in the sample Makefile) and "-L/usr/X11R6/lib" (SRGP pre-dates X11R6).

5. After you do all this, you can successfully build an SRGP app under Linux/X11R6.

I was not, however, able to successfully run it. For starters, it defaults to some assumptions about colormaps which don't appear to be true for contemporary X11 servers. Changing the 4th parameter from "3" to "0" didn't help. It's unclear what - if any - further problems csst0136 might run into if he were to debug the colormap problem.

'Hope that helps ... at least a little!

Any recommendations on a good API for "Learning Graphics 101 under Linux"? My top vote would be for Java (which has very good 2D and 3D APIs), but I'm very curious about SDL.

Do you have any recommendations, deiussum?

deiussum 10-24-2005 05:18 PM

Good findings, paulsm. I'm not at home right now so I can't mess with this srgp API at all myself.

Personally, I like OpenGL since most of the graphics I do is 3D based. (You can do 2D stuff too in the form of textured quads, but if you're looking for a typical 2D API it's probably not what you want.) With OpenGL, however, you still need a windowing API of some sort as it leaves window creation/events/etc. up to someone else. SDL is pretty good for creating a simple OpenGL window, but you can use pretty much any windowing API if you know what you are doing.

csst0136 10-25-2005 08:24 AM

thanx a lot for helping me you already help me a lot especially to paulsm4 and deiussum

the problem has solved to run the examples.i just change the depth color from 16 bit to 8 bit from YAST.SRGP runs only for 8 bit.But the strange thing is that when i run the program it opens
a new window which is the place where i draw what the program does but everything becomes black.I can see just the bounds of the windows,the minimize and close button at top right of the window and the mouse cursor with white color.If i click out of the window then all becomes with color(very fine) but when i click into the window again it becomes all black again and what i draw is with white color.

paulsm4 10-25-2005 09:36 PM

Hi -

I suspect the problem with the "weird colors" is a combination of:

1. The library assumes an excessively low color resolution (you had to go into YaST2 and set the X server to 8-bit/256 color mode?)
... and ..
2. The library is using private (instead of shared) colors.

Again, this was all common practice 10 years ago ... but technology has changed.

I'm afraid I don't have time to go poking around SRGP myself to see if I can make it a little more "Linux-circa-2005-friendly". You're certainly welcome to try; I'd definitely encourage to you to post any questions to LQ.

I couldn't find any good, short web articles on Xlib colormaps that didn't have a lot of extraneous stuff but, if you're feeling ambitious, here are some links that'll tell you everything you need to know ... and then some!

... and ...

'Hope that helps .. PSM

All times are GMT -5. The time now is 12:25 AM.