Gcc Error Undefined Reference
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 the company Business Learn more
Undefined Reference To In C
about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users gcc undefined reference to function Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping
Undefined Reference To G++
each other. Join them; it only takes a minute: Sign up C error: undefined reference to function, but it IS defined up vote 23 down vote favorite 8 Just a simple program, but I keep getting this compiler error. how to solve undefined reference error in c I'm using MinGW for the compiler. Here's the header file, point.h: //type for a Cartesian point typedef struct { double x; double y; } Point; Point create(double x, double y); Point midpoint(Point p, Point q); And here's point.c: //This is the implementation of the point type #include "point.h" int main() { return 0; } Point create(double x, double y) { Point p; p.x = x; p.y = y; return p; } Point midpoint(Point p, Point q) { undefined reference c++ Point mid; mid.x = (p.x + q.x) / 2; mid.y = (p.y + q.y) / 2; return mid; } And here's where the compiler issue comes in. I keep getting: testpoint.c: undefined reference to 'create(double x, double y)' While it is defined in point.c. This is a separate file called testpoint.c: #include "point.h" #include
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
Undefined Reference To A Function C++
Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation c undefined reference to function in header file Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just
C Undefined Reference To Pthread_create
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 down vote favorite 7 Why am http://stackoverflow.com/questions/5559250/c-error-undefined-reference-to-function-but-it-is-defined 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 -c external.c $ gcc -shared -o libexternal.so external.o $ http://stackoverflow.com/questions/8140494/why-am-i-getting-a-gcc-undefined-reference-error-trying-to-create-shared-objec 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-as-needed -lexternal -o program program.c The latter of which passes --no-as-needed to the linker, which would cause the libr
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 workings http://askubuntu.com/questions/194193/why-do-i-get-undefined-reference-errors-when-linking-against-openssl 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 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 it works: Anybody can undefined reference 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