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.

1243 questions
2238
votes
19 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
  • 29,070
  • 19
  • 57
  • 70
1782
votes
39 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 do I fix and prevent these errors?
268
votes
16 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
  • 8,951
  • 14
  • 50
  • 63
140
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) =…
kettlepot
  • 10,574
  • 28
  • 71
  • 100
132
votes
5 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
  • 3,334
  • 14
  • 47
  • 68
131
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
  • 12,815
  • 19
  • 97
  • 126
125
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
  • 27,571
  • 51
  • 138
  • 205
110
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
  • 3,510
  • 7
  • 32
  • 51
108
votes
6 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
  • 1,194
  • 2
  • 8
  • 10
88
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
  • 17,283
  • 39
  • 116
  • 170
71
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
  • 1,023
  • 2
  • 14
  • 27
61
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,719
  • 2
  • 13
  • 20
58
votes
7 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
  • 601
  • 1
  • 5
  • 7
56
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
  • 571
  • 3
  • 7
  • 10
54
votes
8 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
  • 1,009
  • 2
  • 11
  • 18
1
2 3
82 83