![]() |
| | #1 |
| Registered User Join Date: Dec 2005
Posts: 167
| gcc link external library Code: [b12573@iptel7] __linux_build_tmp $ gcc -o test test.c libMGCL.a -Wall test.c: In function `main': test.c:8: warning: implicit declaration of function `yyparse' /usr/bin/ld: libMGCL.a(MGCL_parser.o): Relocations in generic ELF (EM: 20) libMGCL.a: could not read symbols: File in wrong format collect2: ld returned 1 exit status test.c Code: #include <stdio.h>
int main()
{
printf("Hello world\n");
yyparse();
return 0;
}
Where do I go wrong? I don't know very much about linking libraries and such! |
| spank is offline | |
| | #2 |
| Deathray Engineer Join Date: Mar 2007
Posts: 3,211
| Try including the necessary header file for the function.
__________________ |
| MacGyver is offline | |
| | #3 |
| and the hat of vanishing Join Date: Aug 2001 Location: The edge of the known universe
Posts: 21,214
| > libMGCL.a: could not read symbols: File in wrong format This is your first big problem, where did you get that library from? To search a library, the command syntax would be gcc -o test test.c -L. -lMGCL -Wall The -L tells the linker where to look for more libraries The -l tells the linker the name of a library, in this case libMGCL.a Oh, and avoid calling your programs 'test', because there is a standard command called 'test' which appears to do nothing if you don't supply any command line parameters to it.
__________________ If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut. Up to 8Mb PlusNet broadband from only £5.99 a month! |
| Salem is offline | |
| | #4 |
| Registered User Join Date: Dec 2005
Posts: 167
| is there any tool for showing me the content of a library ? some info's about it or anything ? |
| spank is offline | |
| | #5 |
| and the hat of vanishing Join Date: Aug 2001 Location: The edge of the known universe
Posts: 21,214
| The 'ar' tool will list the members of the library. The 'nm' tool will list all the symbols in a library / object file / executable.
__________________ If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut. Up to 8Mb PlusNet broadband from only £5.99 a month! |
| Salem is offline | |
| | #6 | |
| Frequently Quite Prolix Join Date: Apr 2005 Location: Canada
Posts: 7,629
| The command file might tell you what type of library that is. Quote:
Code: $ help test
test: test [expr]
Exits with a status of 0 (true) or 1 (false) depending on
the evaluation of EXPR. Expressions may be unary or binary. Unary
expressions are often used to examine the status of a file. There
are string operators as well, and numeric comparison operators.
File operators:
-a FILE True if file exists.
-b FILE True if file is block special.
-c FILE True if file is character special.
-d FILE True if file is a directory.
-e FILE True if file exists.
-f FILE True if file exists and is a regular file.
-g FILE True if file is set-group-id.
-h FILE True if file is a symbolic link.
-L FILE True if file is a symbolic link.
-k FILE True if file has its `sticky' bit set.
-p FILE True if file is a named pipe.
-r FILE True if file is readable by you.
-s FILE True if file exists and is not empty.
-S FILE True if file is a socket.
-t FD True if FD is opened on a terminal.
-u FILE True if the file is set-user-id.
-w FILE True if the file is writable by you.
-x FILE True if the file is executable by you.
-O FILE True if the file is effectively owned by you.
-G FILE True if the file is effectively owned by your group.
-N FILE True if the file has been modified since it was last read.
FILE1 -nt FILE2 True if file1 is newer than file2 (according to
modification date).
FILE1 -ot FILE2 True if file1 is older than file2.
FILE1 -ef FILE2 True if file1 is a hard link to file2.
String operators:
-z STRING True if string is empty.
-n STRING
STRING True if string is not empty.
STRING1 = STRING2
True if the strings are equal.
STRING1 != STRING2
True if the strings are not equal.
STRING1 < STRING2
True if STRING1 sorts before STRING2 lexicographically.
STRING1 > STRING2
True if STRING1 sorts after STRING2 lexicographically.
Other operators:
-o OPTION True if the shell option OPTION is enabled.
! EXPR True if expr is false.
EXPR1 -a EXPR2 True if both expr1 AND expr2 are true.
EXPR1 -o EXPR2 True if either expr1 OR expr2 is true.
arg1 OP arg2 Arithmetic tests. OP is one of -eq, -ne,
-lt, -le, -gt, or -ge.
Arithmetic binary operators return true if ARG1 is equal, not-equal,
less-than, less-than-or-equal, greater-than, or greater-than-or-equal
than ARG2.
$
__________________ dwk Seek and ye shall find. quaere et invenies. "Simplicity does not precede complexity, but follows it." -- Alan Perlis "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra "The only real mistake is the one from which we learn nothing." -- John Powell Other boards: DaniWeb, TPS Unofficial Wiki FAQ: cpwiki.sf.net My website: http://dwks.theprogrammingsite.com/ Projects: codeform, xuni, atlantis, etc. New project: nort | |
| dwks is offline | |
| | #7 |
| Senior software engineer Join Date: Mar 2007 Location: Portland, OR
Posts: 5,381
| Listing the .a file directly on the link line is also perfectly legitimate. |
| brewbuck is offline | |
![]() |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| What's an import library? | chiefmonkey | C++ Programming | 1 | 06-19-2009 05:00 PM |
| Property Set Library (PSL) - Announcement | vultur_gryphus | Projects and Job Recruitment | 0 | 05-29-2008 06:04 AM |
| Problem calling external method from within a shared library | Major Tom | C++ Programming | 0 | 04-21-2007 09:14 AM |
| Function to check memory left from malloc and free? | Lechx | C Programming | 4 | 04-24-2006 05:45 AM |
| Link list library | Brighteyes | C Programming | 4 | 05-12-2003 08:49 PM |