Questions tagged [undefined-reference]

A linker error caused by a missing definition of a symbol used elsewhere in a program

The most common causes are

  • Declaring but not defining a function, global variable or static data member
  • Not compiling or linking to an object file that contains the definition of a symbol
  • Forgetting to link to the library that provides the symbol
  • Listing a required library before the objects that depend on it (in the linker command libraries should be listed after the objects that depend on them)

There is a C++ FAQ question about undefined references in C++ and how to solve them.

1120 questions
1948
votes
17 answers

Why can templates only be implemented in the header file?

Quote from The C++ standard library: a tutorial and handbook: The only portable way of using templates at the moment is to implement them in header files by using inline functions. Why is this? (Clarification: header files are not the only…
MainID
  • 25,722
  • 19
  • 53
  • 70
1613
votes
36 answers

What is an undefined reference/unresolved external symbol error and how do I fix it?

What are undefined reference/unresolved external symbol errors? What are common causes and how to fix/prevent them?
228
votes
14 answers

libpthread.so.0: error adding symbols: DSO missing from command line

When I'm compiling openvswitch-1.5.0, I've encountered the following compile error: gcc -Wstrict-prototypes -Wall -Wno-sign-compare -Wpointer-arith -Wdeclaration-after-statement -Wformat-security -Wswitch-enum -Wunused-parameter…
jaeyong
  • 7,966
  • 10
  • 44
  • 56
128
votes
6 answers

Undefined reference to `pow' and `floor'

I'm trying to make a simple fibonacci calculator in C but when compiling gcc tells me that I'm missing the pow and floor functions. What's wrong? Code: #include #include int fibo(int n); int main() { printf("Fib(4) =…
Gabriele Cirulli
  • 9,534
  • 23
  • 65
  • 97
112
votes
4 answers

Undefined reference to `sin`

I have the following code (stripped down to the bare basics for this question): #include #include double f1(double x) { double res = sin(x); return 0; } /* The main function */ int main(void) { return 0; } When…
robintw
  • 24,689
  • 48
  • 125
  • 196
101
votes
4 answers

Undefined reference to a static member

I'm using a cross compiler. My code is: class WindowsTimer{ public: WindowsTimer(){ _frequency.QuadPart = 0ull; } private: static LARGE_INTEGER _frequency; }; I get the following error: undefined reference to…
kakush
  • 2,836
  • 14
  • 43
  • 63
98
votes
2 answers

undefined reference to template function

I have three files . The contents of main.cpp are #include #include #include "util.h" int main() { using Util::convert2QString; using namespace std; int n =22; QString tmp = convert2QString(n); return…
Vihaan Verma
  • 11,446
  • 17
  • 84
  • 120
77
votes
4 answers

C error: undefined reference to function, but it IS defined

Just a simple program, but I keep getting this compiler error. 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…
upswimsdn
  • 874
  • 1
  • 6
  • 8
71
votes
5 answers

Undefined reference to sqrt (or other mathematical functions)

I have this simple code: max = (int) sqrt (number); and in the header I have: #include But application still says undefined reference to sqrt. Do you see any problem here? It looks like everything should be okay.
Waypoint
  • 15,705
  • 36
  • 110
  • 167
66
votes
1 answer

DSO missing from command line

I am trying to compile a C++ program like this: $ g++ -o Sniffer_Train main.cpp Sniffer_train.cpp Sniffer_train.h -lmysqlclient -lpcap However I get the following error: /usr/bin/ld: /tmp/cct6xeXD.o: undefined reference to…
srai
  • 953
  • 2
  • 13
  • 23
62
votes
1 answer

How to properly link libraries with cmake?

I can't get the additional libraries I am working with to link into my project properly. I am using CLion, which uses cmake to build it's projects. I am trying to use several libraries in conjunction with OpenGL to texture some objects. I initially…
Cache Staheli
  • 2,897
  • 6
  • 30
  • 41
55
votes
2 answers

gcc: undefined reference to

I would like to compile this. program.c #include int main(){ int i = avpicture_get_size(AV_PIX_FMT_RGB24,300,300); } Running this gcc -I$HOME/ffmpeg/include program.c gives error /tmp/ccxMLBme.o: In function…
jamie_y
  • 1,201
  • 2
  • 11
  • 19
47
votes
5 answers

Undefined symbols "vtable for ..." and "typeinfo for..."?

Nearly the final step but still some strange erros.... bash-3.2$ make g++ -Wall -c -g Myworld.cc g++ -Wall -g solvePlanningProblem.o Position.o AStarNode.o PRM.o PRMNode.o World.o SingleCircleWorld.o Myworld.o RECTANGLE.o CIRCLE.o -o…
Lisa
  • 481
  • 3
  • 7
  • 10
47
votes
5 answers

How to resolve __gcov_init undefined reference issue when linking

I now work on C code coverage study and encountered following issue, GCC version 4.4.6: Added compiler flag CFLAGS = --coverage and linker option LDFLAGS := --coverage or LOCAL_LDLIBS := --coverage and got the error: undefined reference to…
lilingmzai
  • 491
  • 1
  • 4
  • 7
42
votes
6 answers

crt1.o: In function `_start': - undefined reference to `main' in Linux

I am porting an application from Solaris to Linux The object files which are linked do not have a main() defined. But compilation and linking is done properly in Solaris and executable is generated. In Linux I get this error …
Blackforest
  • 759
  • 2
  • 8
  • 17
1
2 3
74 75