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
12
votes
4 answers

Undefined reference - despite lib being found by linker

I have a trivial program to test for availability of python development files: #include int main(){Py_Initialize(); Py_Finalize(); } I compile it (with python 2.7 installed) as gcc -I/usr/include/python2.7 -lpython2.7 p.c. It works fine…
eudoxos
  • 18,545
  • 10
  • 61
  • 110
11
votes
1 answer

undefined reference to `gzopen` error

My C program uses some zlib functions (like gzopen, gzread). I have included the zlib.h header file in my program and added the -lz option when compiling, but I still get an error that the gz functions have undefined references. I'm using kubuntu…
jay1189947
  • 201
  • 1
  • 2
  • 9
11
votes
4 answers

undefined reference when using extern

I have the following setup (hopefully this is not too bare an example): A.h typedef std::map MyClass; extern MyClass inst; A.cpp MyClass inst; B.h #include void foo(); B.cpp #include void foo { …
Amir Rachum
  • 76,817
  • 74
  • 166
  • 248
11
votes
2 answers

Undefined reference to 'inflateInit2_'

I'm using Code Blocks IDE and I want to install Tiled Map Editor for SFML. So, I downloaded the source and imported it to my project. Unfortunately, the build finished with an error due to missing zlib library. I downloaded it and built again. This…
Jake
  • 633
  • 1
  • 7
  • 19
11
votes
1 answer

glfw3 compiling undefined references

I have a problem with compiling my program which uses glfw3 library. I'm getting list of errors of undefined references when trying to compile with make but my classes are compiled into .o files, only final executable file is not…
mezo
  • 423
  • 1
  • 7
  • 19
11
votes
2 answers

Why is curses on linux giving me following error?

Trying to get getch() working to capture key press. #include ... ... WINDOW *w; char f; w = initscr(); timeout(3000); f = getch(); endwin(); is giving me following error:- undefined reference to…
Alex Xander
  • 3,903
  • 14
  • 36
  • 43
10
votes
1 answer

Undefined OLE references in external library even when linking with libole32

Using MINGW, I'm trying to link my C code with a static C++ library that performs some OLE operations: mingw32-gcc main.o resources.o -o mbcom.exe -L../../Lib/Iup -liup -liupole -lole32 -lcomctl32 -lstdc++ -mwindows Unfortunately, I get…
David Brown
  • 35,411
  • 11
  • 83
  • 132
10
votes
2 answers

gcc undefined reference to

I'm running.. gcc -c -I/usr/vt/sample ttssample.c gcc -L. -lttsapi ttssample.o -o ttsample and I'm getting the following error... ttssample.o: In function `_TTSFile': ttssample.c:(.text+0x352): undefined reference to `TTSRequestFile' ttssample.o:…
JLB
  • 105
  • 1
  • 1
  • 7
10
votes
1 answer

cmake undefined reference to function

The project structure below is a simplified example. I tried to boil it down to the minimal amount of files to reproduce my issue. . ├── CMakeLists.txt ├── subdir1 │   ├── CMakeLists.txt │   └── subsubdir1 │   ├── CMakeLists.txt │   ├──…
E-rich
  • 9,243
  • 11
  • 48
  • 79
10
votes
1 answer

Undefined symbol error importing Cython module

I want to make available one of my c++ classes as Python module. The class is declared in a header Foo.h and implemented in a .cpp Foo.cpp. (g++-4.5, Ubuntu x86_64). It's a very very simple class: Foo.cpp: Foo::Foo() : alfa(1.0),…
linello
  • 8,451
  • 18
  • 63
  • 109
9
votes
5 answers

Should a virtual function essentially have a definition?

Is it essential to have a definition for a virtual function? Consider this sample program below: #include using namespace std; class base { public: void virtual virtualfunc(); }; class derived : public base { public: …
nitin_cherian
  • 6,405
  • 21
  • 76
  • 127
9
votes
3 answers

ubuntu and libcap (capabilities) undefined reference

I'm trying to compile the following minimal C code on ubuntu 10.10: #include void main(void) { cap_t cap; cap = cap_get_proc(); } with gcc -lcap test.c which gives me the following error: /tmp/ccCQFyXS.o: In…
kuroneko
  • 425
  • 2
  • 4
  • 10
9
votes
4 answers

How to include data object files (images, etc.) in program and access the symbols?

I've turned a couple of resource files into .obj files using objcopy and i link them with my programs source code. I can very well access the symbols inside the object file in my program with the following code, but only with GCC/G++…
chakmeshma
  • 246
  • 8
  • 27
9
votes
8 answers

Compiler error with yaml-cpp - undefined reference to `YAML::detail::node_data::convert_to_map`

Here's the complete log: /tmp/ccCvErNZ.o: In function `YAML::detail::node& YAML::detail::node_data::get(std::string const&,…
apoorvumang
  • 169
  • 1
  • 2
  • 8
9
votes
2 answers

Undefined reference to memcpy_s

I'm trying to fix an undefined reference to memcpy_s() error. I've included string.h in my file and the memcpy() function works okay, and I've also tried including memory.h. I'm on x64 Windows 7 and using gcc 4.8.1 to compile. #include…
hydrazone
  • 111
  • 1
  • 1
  • 5