LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 08-03-2005, 07:48 PM   #1
gavinbeatty
Member
 
Registered: Nov 2003
Posts: 79

Rep: Reputation: Disabled
liberror.h linking


Using the slackpack for liberror.h available on linuxpackages.net I get very verbose error output when trying to compile very simple use of the fundamentals of the library.

I've been doing
Code:
gcc err.c -o err -lerror
The file err.c is as follows:
Code:
#include <liberror.h>

int main (int argc, char **argv)
{
	err_init(&argc, &argv);
	err_add_stream (C_TAG_ALL, stdout, NULL);
	
	eprintf(C_TAG_BANNER, 0, "This is a test to see if I can compile");
}
I get HUGE output of:

/usr/lib/gcc-lib/i486-slackware-linux/3.3.4/../../../liberror.a(err_map_char_p_char_p.o)(.text+0x600e): In function `err_map_char_p_char_p_remove_internal(err_map_char_p_char_p_t*, char*, char**)':
src/err_map_char_p_char_p.cpp:4226: undefined reference to `operator delete(void*)'
/usr/lib/gcc-lib/i486-slackware-linux/3.3.4/../../../liberror.a(err_map_char_p_char_p.o)(.text+0x1d75): In function `err_map_char_p_char_p_free_sorted_iterator':
src/err_map_char_p_char_p.cpp:6128: undefined reference to `operator delete[](void*)'
/usr/lib/gcc-lib/i486-slackware-linux/3.3.4/../../../liberror.a(err_map_char_p_char_p.o)(.text+0x1d95): In function `err_map_char_p_char_p_free_sorted_iterator_ptr':
src/err_map_char_p_char_p.cpp:6134: undefined reference to `operator delete[](void*)'
/usr/lib/gcc-lib/i486-slackware-linux/3.3.4/../../../liberror.a(err_map_char_p_char_p.o)(.text+0x595a): In function `err_map_char_p_char_p_destroy_internal(err_map_char_p_char_p_t*)':
src/err_map_char_p_char_p.cpp:4549: undefined reference to `operator delete(void*)'
/usr/lib/gcc-lib/i486-slackware-linux/3.3.4/../../../liberror.a(err_map_char_p_char_p.o)(.text+0x5a81): In function `err_map_char_p_char_p_destroy_internal_flags(err_map_char_p_char_p_t*, unsigned char, unsigned char)':
src/err_map_char_p_char_p.cpp:4568: undefined reference to `operator delete(void*)'
/usr/lib/gcc-lib/i486-slackware-linux/3.3.4/../../../liberror.a(style-qt.o)(.eh_frame+0x11): undefined reference to `__gxx_personality_v0'
/usr/lib/gcc-lib/i486-slackware-linux/3.3.4/../../../liberror.a(style-qt3.o)(.eh_frame+0x12): undefined reference to `__gxx_personality_v0'
collect2: ld returned 1 exit status

and with much more than my terminal can scroll up aswell.

Is this an error in how liberror.h was compiled or have I got linking done incorrectly? It's my first time linking.

edit: I've tried compiling liberror on my own in Slack 10.1 and I get errors but the tgz is from a reputable packager and seems to work otherwise. ie the binaries it installs are fully functional

Last edited by gavinbeatty; 08-03-2005 at 07:50 PM.
 
Old 08-03-2005, 09:50 PM   #2
Tomasfuego
Member
 
Registered: Nov 2002
Location: USA
Distribution: Lenny at work
Posts: 168

Rep: Reputation: 30
Does eprintf work? I just checked the site and it says that you can use that function from a shell.

Where did the library install to? Try
whereis liberror

Try also linking directly to that library with the -L/whereever/liberror.so option

To capture the output on the compile, you could do it inside an IDE like eclipse or in the shell you can do something like this:
gcc ... 2>1 &> log.txt

If i understand it right, all stderr (2) is directed back to stdout(1) and then stdout is put into log.txt
 
Old 08-04-2005, 11:39 AM   #3
gavinbeatty
Member
 
Registered: Nov 2003
Posts: 79

Original Poster
Rep: Reputation: Disabled
Yes, eprintf (in bash) works perfectly.

Also, I have no liberror.so or error.so. I only have a liberror.a and liberror.h in /usr/lib and /usr/include respectively.

I have only ever come across -lm for use of math.h. I have only previously used math.h, stdio.h, stdlib.h, string.h, time.h and only math.h (and seemingly randomly) requires a -l type option.

Thanks for your help so far. I've at least learned a bit about bash!

Last edited by gavinbeatty; 08-04-2005 at 11:42 AM.
 
Old 08-04-2005, 07:43 PM   #4
Tomasfuego
Member
 
Registered: Nov 2002
Location: USA
Distribution: Lenny at work
Posts: 168

Rep: Reputation: 30
what does your gcc output look like?

also, with *.a libraries, I believe you include that directly and use the -l for shared libraries that liberror needs, so

gcc err.c -o err /path/to/liberror.a -lneeded_libraries_if_any
 
Old 08-05-2005, 10:12 AM   #5
gavinbeatty
Member
 
Registered: Nov 2003
Posts: 79

Original Poster
Rep: Reputation: Disabled
gcc output ising your bash method is identical to what I already posted.
I checked the man pages and it's 0, 1, 2 for stdin, stdout and stderr respectively so I don't think the wrong output is being directed to right place or vice-versa.

I tried
Code:
gcc err.c -o err /usr/lib/liberror.a -lerror
and
Code:
gcc err.c -o err /usr/lib/liberror.a -lliberror
and the same tow with -L in front of /usr/lib/liberror.a, but I get the exact same output from gcc (and no executable as usual) as without -L/usr/lib/liberror.a

Also, the gcc man page says -lerror should find /usr/lib/liberror.a as it automatically scans relevant dirs and adds lib and .a to start and end respectively. It says I should use -L/usr/lb/liberror.a OR -lerror.

Problem is, neither seem to work.

I hope people have more suggestions because I'm pretty stumped. I'll try look into my installation of the library and header but I think I have some small compiling problem

Last edited by gavinbeatty; 08-05-2005 at 10:14 AM.
 
Old 08-05-2005, 11:36 AM   #6
gavinbeatty
Member
 
Registered: Nov 2003
Posts: 79

Original Poster
Rep: Reputation: Disabled
Well I removed the tgz and compiled successfully from source with --prefix=/usr and tried
Code:
gcc err.c -I/usr/include -L /usr/lib/liberror.a -lerror -lm -o err
and a few other variants with the exact same problems.

Any ideas? I'm quite stuck.

Think I'm gonna try make a custom SLAX live-cd and see what happens.

Still, the matter is by no means closed

Thanks for your help so far Tomasfuego
 
Old 08-05-2005, 12:09 PM   #7
deiussum
Member
 
Registered: Aug 2003
Location: Santa Clara, CA
Distribution: Slackware
Posts: 895

Rep: Reputation: 32
try:

gcc err.c -o err -lerror -lm -static

The static flag usually tells gcc to use .a files instead of .so. The -L parameter is usually just used when you need to include additional library search paths. For instance if your liberror librar was in /usr/local/error/lib you would add -L/usr/local/error/lib so that that path would be searched as well for the libraries.
 
Old 08-05-2005, 12:19 PM   #8
deiussum
Member
 
Registered: Aug 2003
Location: Santa Clara, CA
Distribution: Slackware
Posts: 895

Rep: Reputation: 32
I downloaded that package to try and compile your test code there and found that I had to use g++ instead of gcc. It appears that the liberror package uses stuff from the standard C++ library, so if you use gcc w/o including the standard C++ libraries, it complains about undefined references to things like operator delete[]...

Anyway, your test code compiled nicely with the following:

g++ err.c -o err -lerror -static

Edit: I just tried it w/o the -static flag and it compiles cleanly that way too, so long as you use g++. That was probably your problem all along.

Edit 2: The reason it compiles cleanly with g++ and not with gcc might not even be because it is trying to link to stuff in the standard C++ library. More likely, the stuff in the .a file itself has C++ style name mangling, which is much different from the C-style name decorations.

Last edited by deiussum; 08-05-2005 at 12:24 PM.
 
Old 08-06-2005, 03:08 PM   #9
gavinbeatty
Member
 
Registered: Nov 2003
Posts: 79

Original Poster
Rep: Reputation: Disabled
Thanks deiussum, problem solved.
 
Old 08-06-2005, 04:22 PM   #10
gavinbeatty
Member
 
Registered: Nov 2003
Posts: 79

Original Poster
Rep: Reputation: Disabled
Sorry, this is kind of off-topic now but using g++ throws up a compile error when trying to use liberror.h for what I originally intended.

I have a program that has all sorts of functions to do with SuDoku tables and was using argp.h for passing arguments from the command line.

Now, in parse_opt (NOTE: prototype: static error_t parse_opt (int key, char *arg, struct argp_state *state)) doing
Code:
struct arguments *arguments = state->input;
gives me an error where the compiler says

su_argp.c: In function `error_t parse_opt(int, char*, argp_state*)':
su_argp.c:45: error: invalid conversion from `void*' to `arguments*'


Why does this appear when using C++? I had hoped I could simply try use my C knowledge (limited) and know that C++ is simply a superset of C so everything should be fine.

If argp.h isn't really for C++ at all, can you recommend a similar system?
 
Old 08-06-2005, 05:29 PM   #11
deiussum
Member
 
Registered: Aug 2003
Location: Santa Clara, CA
Distribution: Slackware
Posts: 895

Rep: Reputation: 32
You likely need to use casting somewhere. The C++ compilers are generally a bit stricter on matching types than C compilers. I'm assuming that your state->input value is declared as a void*. Try changing that line to:

struct arguments *arguments = (arguments*)state->input;

Note that this is the C-style casting and C++ has other preferred methods of casting, but should work for your current problem. If you want to learn more about the new C++ style casting look into static_cast, dynamic_cast, reinterpret_cast, and const_cast...
 
Old 08-07-2005, 07:12 AM   #12
gavinbeatty
Member
 
Registered: Nov 2003
Posts: 79

Original Poster
Rep: Reputation: Disabled
Thanks for your help again! Forgot all about casting - only ever read about it in a tutorial on the web and didn't really remember it obviously.

What you gave me didn't actually compile but
Code:
struct arguments *arguments = (struct arguments*)state->input;
did.

But that's really something you almost always miss until you actually compile the damn thing.

Thanks again. I actually learned a few things from all this.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Linking Problems doubleds Linux - Software 4 12-03-2004 09:49 PM
linking directories david@aber Linux - Newbie 3 11-25-2004 07:45 AM
Linking LS to 'L' uveraser Linux - General 2 05-20-2004 10:24 AM
Linking Python and C++ irfanhab Programming 2 05-15-2004 01:22 PM
C++ linking? ugenn Programming 5 05-14-2002 01:33 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:36 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration