Gcc Linker Error
Contents |
here for a quick overview of the site Help Center Detailed answers to any gcc linker undefined reference questions you might have Meta Discuss the workings and policies of gcc undefined reference to function this site About Us Learn more about Stack Overflow the company Business Learn more about hiring
Linking Undefined Reference To
developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is
Undefined Reference Gcc
a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Linker error on Linux: “undefined reference to” up vote 10 down vote favorite 1 I am able to make a shared library without problems. I create libcbitcoin.so (with no errors) and linker error undefined reference to attempt to link against it with an executable as well as OpenSSL libraries. I use this command: gcc -L/media/sf_BitEagle_Projects/cbitcoin/build/bin -lcbitcoin \ -Wl-rpath,/media/sf_BitEagle_Projects/cbitcoin/build/bin -lssl -lcrypto \ -L/usr/local/ssl/lib/ -o /media/sf_BitEagle_Projects/cbitcoin/build/bin/testCBAddress \ /media/sf_BitEagle_Projects/cbitcoin/build/obj/testCBAddress.o \ /media/sf_BitEagle_Projects/cbitcoin/build/obj/CBOpenSSLCrypto.o The bin directory is the location of the library. The obj directory has the object files I wish to link into an executable. In the command I use the -L, -l and -rpath options which I thought was all that is needed for linking in linux. It seems I am wrong since I get errors like: /media/sf_BitEagle_Projects/cbitcoin/test/testCBAddress.c:40: undefined reference to `CBNewByteArrayFromString' CBNewByteArrayFromString is found in the library. For some reason it is not being linked. OpenSSL too: /media/sf_BitEagle_Projects/cbitcoin/dependencies/crypto/CBOpenSSLCrypto.c:37: undefined reference to `SHA1' How do I get the linking to work? GCC version: gcc (Ubuntu/Linaro 4.6.3-1ubuntu5) 4.6.3 On Linux Mint 13 Thank you. linux gcc build linker share|improve this question edited Sep 5 '12 at 0:19 choroba 106k1089146 asked Sep 5 '12 at 0:01 Ma
Web Development GUI Toolkits/Desktop Databases Mail Systems openSolaris Eclipse Documentation Techotopia.com Virtuatopia.com How To Guides Virtualization General System Admin Linux Security Linux Filesystems Web Servers Graphics & Desktop PC Hardware Windows
.so: Undefined Reference To
Problem Solutions <<< previous table of contents next g++ undefined reference to >>> 13.3 Linker error messages file not recognized: File format not recognized GCC uses the extension of a file, undefined reference to c such as '.c' or '.cc', to determine its content. If the extension is missing GCC cannot recognize the file type and will give this error. Example: #include
can easily range from 50 to 75 percent of the total development cost."1 While this is not a course about the software development life cycle http://web.ics.purdue.edu/~cs240/misc/errors.html it is our goal to teach you good software development technique. The errors that you typically experience are one of three types: Compiler Errors Linker Errors Run Time http://www.csee.umbc.edu/courses/undergraduate/202/fall04/Projects/CommonErrors.shtml Errors lets examine these three types of errors in more detail. Compiler Errors Compiler errors are caused by incorrect syntax. This means that you have not followed the undefined reference basic rules of C. These basic rules are things like: putting a semicolon at the end of a line writing a proper function header passing the correct number and type of arguments to a function matching up all pairs of braces {} and parentheses () not using variables that you haven't declared declaring all variables at the top of a undefined reference to function many, many more When you run the compiler on your code it first does any preprocessing (that is any line that begins with #). Then it checks the syntax of your code. In other words it makes sure that you have followed all the rules of C. If you haven't it prints out an error so that you can fix your syntax. Unfortunately most new users find the messages sent back from gcc confusing. So we will go over some common gcc error messages, what they mean, and how to fix them. General compile-time error and warning description In C, a compilation error is usually fatal, meaning that the C compiler cannot compile the source code. A warning, on the other had, is usually just that. The compiler has identified that there may be a problem, but it can produce object code anyway. Warnings should not be ignored, because they usually do indicate that there is something wrong with the program, and it is likely to behave differently from what you would expect. Error messages and w
suggestions for errors that should be included in this document or have questions or suggestions for improving the document please email Mr. Frey Definitions Commonly used words and phrases found in the compiler and linker error messages. identifier -- the name of a class, struct, function or variable collect2: ld returned 1 exit status -- usually found as the last line of the error. This phrase indicates that you have a linker (ld) error, not a compiler error. Linker errors occur when g++ tries to combine all of your .o files into an executable file. Linker errors CANNOT be fixed by guarding header files or by changing which header files are included in your .cpp file. non-aggregate type -- classes and structs are generically called "aggregate" types. If you get an error indicating that your class is a "non-aggregate type", then the compiler has not seen your class definition and doesn't recognize your class as such. read-only structrure -- refers to a const object. This phrase is generally found in a compiler error when you are trying to change a data member in a const object. Compiler Errors undeclared identifier Example doy.cpp: In function `int main()': doy.cpp:25: `DayOfYear' undeclared (first use this function) doy.cpp:25: (Each undeclared identifier is reported only once for each function it appears in.) doy.cpp:25: parse error before `;' token Meaning You used "DayOfYear" in your code, but the compiler has not seen a definition for "DayOfYear". It doesn't know what "DayOfYear" is. Usual Causes You forgot to include the header file that defines the class/struct/function/etc You misspelled the name of the identifier cout undeclared Example xyz.cpp: In function `int main()': xyz.cpp:6: `cout' undeclared (first use this function) xyz.cpp:6: (Each undeclared identifier is reported only once for each function it appears in.) Meaning This is really a special case of "undeclared identifier". Usual causes You forgot to include