Linker Error Undefined Reference To C
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 linker error undefined reference to function in c of this site About Us Learn more about Stack Overflow the company Business undefined reference error in c Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask error undefined reference to c++ Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 6.2 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign
Undefined Reference To Function C++
up Undefined reference to '_*' linker error up vote 0 down vote favorite I am having trouble compiling/linking the following C code. The linker throws errors that look like the following: pso.o:pso.c:(.text+0x41): undefined reference to '_ps' ... pso.o:pso.c:(.text+0x93): more undefined references to '_ps' follow This is my first time writing C code for gcc, so I'm unsure how to fix this problem. undefined reference error in c compilation I am assuming that because struct PS is defined my header file, it is somehow not linked to pso.c. However, I did use a #include "ps.h" statement at the top of that source file. I have included the relevant source files and header file below, as well as the make file I am using. Is there a fundamental concept I am missing for writing linkable C code? Thank you! Oh, and it's a particle swarm optimizer, if you were wondering :) The main.c file: #define MAIN #include here for a quick overview of the site Help Center Detailed answers g++ undefined reference to to any questions you might have Meta Discuss the 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 Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack http://stackoverflow.com/questions/15257120/undefined-reference-to-linker-error Overflow Community Stack Overflow is a community of 6.2 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up “undefined reference to” errors when linking static C library with C++ code up vote 17 down vote favorite 6 I have a test file http://stackoverflow.com/questions/18877437/undefined-reference-to-errors-when-linking-static-c-library-with-c-code (just for the link test) where I overload the new/delete operators with my own malloc/free library called libxmalloc.a. But I keep getting "underdefined reference to" error as following when linking the static library, even I change the order of test.o and -lxmalloc. But everything works well with other C programs linking this library. I'm so confused with this issue and appreciate any clue. Error MSg: g++ -m64 -O3 -I/usr/include/ethos -I/usr/include/nacl/x86_64 -c -o test.o test.cpp g++ -m64 -O3 -L. -o demo test.o -lxmalloc test.o: In function `operator new(unsigned long)': test.cpp:(.text+0x1): undefined reference to `malloc(unsigned long)' test.o: In function `operator delete(void*)': test.cpp:(.text+0x11): undefined reference to `free(void*)' test.o: In function `operator new[](unsigned long)': test.cpp:(.text+0x21): undefined reference to `malloc(unsigned long)' test.o: In function `operator delete[](void*)': test.cpp:(.text+0x31): undefined reference to `free(void*)' test.o: In function `main': test.cpp:(.text.startup+0xc): undefined reference to `malloc(unsigned long)' test.cpp:(.text.startup+0x19): undefined reference to `malloc(unsigned long)' test.cpp:(.text.startup+0x24): undefined reference to `free(void*)' t here for a quick overview of the site Help Center Detailed answers http://stackoverflow.com/questions/12272864/linker-error-on-linux-undefined-reference-to to any questions you might have Meta Discuss the http://stackoverflow.com/questions/26820736/linking-error-undefined-reference-to-functions-thatre-defined-in-a-separate-fi 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 Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the undefined reference Stack Overflow Community Stack Overflow is a community of 6.2 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 undefined reference to 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-1ubuntu5) 4.6.3 On Linux Mint 13 Thank you. linux gcc build linker share|i 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 the company Business Learn more about hiring 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 a community of 6.2 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Linking error: Undefined reference to functions that're defined in a separate file? up vote 1 down vote favorite I'm probably forgetting something obvious that'll solve this. While there's other questions on SO with the same issue, none of the solutions have been applicable to my situation. I have a main file, sim.c, a header file net.h, a header file friends.h, and a file with the functions, net.c. I have a makefile, which I created with gmakemake > Makefile, and its contents are very basic. Header.mak (makefile template): CFLAGS = -Wall -Wextra -pedantic -std=c99 -ggdb LFLAGS = -ggdb LDFLAGS = Makefile relevant contents: CPP_FILES = C_FILES = net.c sim.c PS_FILES = S_FILES = H_FILES = net.h friends.h SOURCEFILES = $(H_FILES) $(CPP_FILES) $(C_FILES) $(S_FILES) .PRECIOUS: $(SOURCEFILES) OBJFILES = # # Main targets # all: net sim net: net.o $(OBJFILES) $(CC) $(CFLAGS) -o net net.o $(OBJFILES) $(CLIBFLAGS) sim: sim.o $(OBJFILES) $(CC) $(CFLAGS) -o sim sim.o $(OBJFILES) $(CLIBFLAGS) # # Dependencies # net.o: net.h sim.o: net.h My sim.c file contains: #include "net.h" #include "friends.h" My header file contains the functions in net.c and defines them all as stubs. I copied and pasted them to create the function headers, so there shouldn't be any typos. My net.c file contains: #include "net.h" Yet any time a function in sim.c tries to call a function in net.c, it errors on that line with: "undefined refHow To Solve Undefined Reference Error In C
Error Undefined Offending Command