Gcc Error Undefined Symbol
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
Undefined Symbol First Referenced In File C++
Stack Overflow the company Business Learn more about hiring developers or posting ads with ld: fatal: symbol referencing errors us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is
Undefined First Referenced Symbol In File Solaris
a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up gcc 4.2.1 Linking issue: Undefined Symbols for Architecture x86_64 up vote 6 down vote gcc undefined symbols for architecture x86_64 favorite 1 Yes, it's been asked before, but every answer I come up with on SO and elsewhere has to do with compiling C++ code in gcc instead of g++, or a issue of some kind with standard libraries. So far, nothing actually lining up right for me here. So, I'm going through a basic crash course on C, and trying to compile an example used to illustrate linking to collect2: ld returned 1 exit status files that you create, rather than from the standard libraries. Here's the code: math_functions.h int sum (int x, int y); float average (float x, float y, float z); math_functions.c int sum (int x, int y) { return (x + y); } float average (float x, float y, float z) { return (x + y + z) / 3; } and finally test3.c #include
here for a quick overview of the site Help Center
Gcc Linker Options
Detailed answers to any questions you might have Meta collect2: error: ld returned 1 exit status Discuss the workings and policies of this site About Us Learn more about Stack
Undefined Reference To
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/17019908/gcc-4-2-1-linking-issue-undefined-symbols-for-architecture-x86-64 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.
volatile char src[] = {1, 2, 3, 4, 5}; volatile char dst[50] = {0}; void* memcpy(void* dst, void* src, int len); int main(int argc, const char* argv[]) { memcpy(dst, src, sizeof(src) / sizeof(src[0])); return dst[4]; } It runs just fine and http://eli.thegreenplace.net/2013/07/09/library-order-in-static-linking the return value is 5. Now, suppose this is part of a larger project that https://ubuntuforums.org/showthread.php?t=1687827 consists of many object files and libraries, and somewhere within the project there's a library that contains this code: void memcpy(char* aa, char* bb, char* cc) { int i; for (i = 0; i < 100; ++i) { cc[i] = aa[i] + bb[i]; } } If the previous snippet gets linked with this library, what happens? Would you expect it to still undefined symbol return 5? Return something else? Crash? The answer is: it depends - the result can be either correct or a segmentation fault. It depends on the order in which the objects and libraries in the project were fed to the linker. If you fully understand why this depends on linking order, as well as how to avoid the problem (and more serious problems, like circular dependencies) then congratulate yourself and move on - this article is probably not ld returned 1 for you. Otherwise, read on. The basics Let's start by defining the scope of this article: first, my examples are demonstrating the use of the gcc and binutils toolchain on Linux. Compatible toolchains (like clang instead of gcc) apply too. Second, the discussion here resolves around static linking that's done at compile/link time. To understand why linking order matters, it's first instructional to understand how the linker works with respect to linking libraries and objects together. Just as a quick reminder - an object file both provides (exports) external symbols to other objects and libraries, and expects (imports) symbols from other objects and libraries. For example, in this C code: int imported(int); static int internal(int x) { return x * 2; } int exported(int x) { return imported(x) * internal(x); } The names of the functions speak for themselves. Let's compile it and look at the symbol table: $ gcc -c x.c $ nm x.o 000000000000000e T exported U imported 0000000000000000 t internal This means: exported is an external symbol - defined in the object file and visible from the outside. imported is an undefined symbol; in other words, the linker is expected to find it elsewhere. When we talk about linking later, the term undefined can become confusing - so it helps to remember that this is where it comes from originally. internal is defined within the object but inv
Get Kubuntu Get Xubuntu Get Lubuntu Get UbuntuStudio Get Mythbuntu Get Edubuntu Get Ubuntu-GNOME Get UbuntuKylin Ubuntu Code of Conduct Ubuntu Wiki Community Wiki Other Support Launchpad Answers Ubuntu IRC Support AskUbuntu Official Documentation User Documentation Social Media Facebook Twitter Useful Links Distrowatch Bugs: Ubuntu PPAs: Ubuntu Web Upd8: Ubuntu OMG! Ubuntu Ubuntu Insights Planet Ubuntu Activity Page Please read before SSO login Advanced Search Forum The Ubuntu Forum Community Ubuntu Specialised Support Development & Programming Programming Talk [SOLVED] compiling with gcc and "undefined reference to xxx" Having an Issue With Posting ? Do you want to help us debug the posting issues ? < is the place to report it, thanks ! Results 1 to 4 of 4 Thread: compiling with gcc and "undefined reference to xxx" Thread Tools Show Printable Version Subscribe to this Thread… Display Linear Mode Switch to Hybrid Mode Switch to Threaded Mode February 14th, 2011 #1 NeillHog View Profile View Forum Posts Private Message Visit Homepage Gee! These Aren't Roasted! Join Date Jul 2007 Location The Bavarian Alps Beans 129 DistroKubuntu 7.10 Gutsy Gibbon compiling with gcc and "undefined reference to xxx" I have run up against a wall. I really appreciate any and all help because I am so out of my depth. I have installed gcc on a NSLU2. Running gcc -o test test.c brings no error and afterwards I can run the program test with ./test. test.c #include