Gcc Undefined Reference Error
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow gcc undefined reference to function the company Business Learn more about hiring developers or posting ads with us Stack undefined reference to in c Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of undefined reference to g++ 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Why am I getting a gcc “undefined reference” error trying to create shared objects? up vote 15 undefined reference to gcc linker error down vote favorite 7 Why am I getting an "undefined reference" error using gcc? I am trying to create a shared object (.so) that exports one function, "external()". I then try to link against the .so but get "undefined reference 'external'". What am I doing wrong here? File: external.c int external() { return 5; } File: program.c int external(); int main(char** argv, int* argc) { return external(); } Commands: $ gcc -fPIC
Undefined Reference C++
-c external.c $ gcc -shared -o libexternal.so external.o $ gcc -L. -lexternal -o program program.c /tmp/cc3MmhAE.o: In function `main': program.c:(.text+0x7): undefined reference to `external' collect2: ld returned 1 exit status I can even run nm and see that the .so is defining 'external': Command: $ nm libexternal.so | grep external 0000040c T external What am I missing here? c gcc ld shared-libraries share|improve this question edited Jul 7 '12 at 12:11 octopusgrabbus 5,57772882 asked Nov 15 '11 at 17:26 Warren 80311120 1 Does gcc -L. -o program program.c -lexternal fix it? –Flexo♦ Nov 15 '11 at 17:28 Ah, yes it does, thank you, but why? Why does -l have to be at the end? –Warren Nov 15 '11 at 17:35 @Warren, do you know of a gcc flag --echo-ld-options i.e. tell me what you're doing ? –denis Nov 20 '12 at 14:04 add a comment| 1 Answer 1 active oldest votes up vote 31 down vote accepted Recent versions of gcc/ld default to linking with --as-needed. This means if you write -lexternal before the C file the library will automatically get excluded (the order matters when testing if things are "needed" like this) You can fix this with either of: gcc -L. -o program program.c -lexternal gcc -L. -Wl,--no-
here for a quick overview of the site Help Center
Gcc Undefined Reference To Static Library
Detailed answers to any questions you might have Meta undefined reference gcc Discuss the workings and policies of this site About Us Learn more about Stack undefined reference to cmake Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question http://stackoverflow.com/questions/8140494/why-am-i-getting-a-gcc-undefined-reference-error-trying-to-create-shared-objec x Dismiss Join the Stack Overflow Community Stack Overflow is 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 http://stackoverflow.com/questions/12272864/linker-error-on-linux-undefined-reference-to to make a shared library without problems. I create libcbitcoin.so (with no errors) and 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-1ubuntu
communities company blog Stack Exchange Inbox Reputation and Badges sign up log in tour help Tour Start here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the http://askubuntu.com/questions/194193/why-do-i-get-undefined-reference-errors-when-linking-against-openssl workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Ask Ubuntu Questions Tags http://www.keil.com/support/docs/3136 Users Badges Unanswered Ask Question _ Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute: Sign up Here's how undefined reference it works: Anybody can ask a question Anybody can answer The best answers are voted up and rise to the top Why do I get “undefined reference” errors when linking against OpenSSL? up vote 4 down vote favorite 1 My compilation process throws around errors like ..undefined reference to `BN_cmp' although I include
30 Days In the Last 90 Days In the Last 6 Months Technical Support Overview Search Contact Assistance Request Feedback Support Resources Support Knowledgebase Article Index Top 10 Articles Product Manuals Application Notes Downloads Product Updates Discussion Forum Books Product Information Software & Hardware Products ARM Development ToolsC166 Development ToolsC51 Development ToolsC251 Development ToolsDebug AdaptersEvaluation Boards Product Brochures Newsletters Home/Technical Support GCC: LINKER ERROR (UNDEFINED REFERENCE WITH C++) Information in this article applies to: GNU C Compiler for ARM All Versions SYMPTOM The GNU linker gives error messages while linking an application which contains class declarations and class instances. CAUSE The class declaration specifies a constructor and/or destructor, but the constructor/destructor function is missing. class clf { public: clf(); // Constructor (ctor) ~clf(); // Destructor (dtor) int n1, n2, n3; }; clf clf1; // class object int main (void) { return (0); } The linker gives the error messages which look like the following ones: .\obj\blinky.o(.text+0x40): In function '__static_initialization_and_destruction_0': /cygdrive/c/Keil/ARM/GNU/Examples/Blinky/blinky.cpp(92): error: undefined reference to 'clf::~clf [in-charge]() 'blinky.o' (.text+0x44):blinky.cpp:92: undefined reference to 'clf::clf[in-charge]()' RESOLUTION Add the constructor(s) and/or destructor(s) as shown below: class clf { public: clf(); // Constructor (ctor) ~clf(); // Destructor (dtor) int n1, n2, n3; }; clf::clf () { // define ctor n1 = n2 = n3 = 0; } clf::~clf() { // define dtor } clf clf1; // class object int main (void) { return (0); } SEE ALSO µVision DEBUGGER: SOURCE LEVEL DEBUGGING WITH GNU ARM Last Reviewed: Monday, December 10, 2012 Did this article provide the answer you needed? Yes No Not Sure Products Development Tools ARM C166 C51 C251 µVision IDE and Debugger Hardware & Collateral ULINK Debug Adaptors Evaluation Boards Product Brochures Device Database Distributors Downloads MDK-ARM C51 C166 C251 File downloads Support Knowledgebase Discussion Forum Product Manuals Application Notes Contact Distributors Request a Quote Sales Contacts Cookie Settings | Terms of Use | Privacy | Accessibility | Contact Us | Feedback Copyright © 2005-2016 ARM Group. All ri