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
5
votes
1 answer

Linking error "undefined reference" about boost static library during compiling

I am trying to compile my C++ project on Linux x64 with boost libraries 1.57. This project is compiled with scons and I successfully compiled it on my Arch Linux, but this time failed on a Ubuntu machine. I added -lboost_coroutine flag for linking…
Han
  • 397
  • 1
  • 6
  • 18
5
votes
1 answer

"undefined reference to `_cmocka_run_group_tests'" when running sample CMocka test

I installed the CMocka testing framework and tried the sample code: #include #include #include #include /* A test case that does nothing and succeeds. */ static void null_test_success(void **state) { …
neo post modern
  • 2,262
  • 18
  • 30
5
votes
2 answers

In function `_start': init.c:(.text+0x30): undefined reference to `main'

I'm working on a C project with around 30 source files (.c). I'm building this project on a 32 bit micro-controller(i.MX515) running on Ubuntu using GNU tools. The compilation phase completes successfully, however when the linking process starts I…
HaggarTheHorrible
  • 7,083
  • 20
  • 70
  • 81
5
votes
1 answer

libTogl undefined references

I am trying to install netgen (build from source). Therefore Togl is needed and I installed it via sudo apt-get install libtogl1 libtogl-dev When typing 'make' I receive the following error…
user3528789
  • 103
  • 7
5
votes
3 answers

"Undefined Reference To 'IMG_Load'" CodeBlocks and SDL_Image Error

I'm learning SDL through Lazy Foo's tutorial, but I can't proceed further as IMG_Load doesn't seem to work. I tried setting it up like he says, but it just doesn't work. I put all the include files into include folder, and all the lib files into the…
user2588543
4
votes
2 answers

Strange Compiler Error: "undefined reference to 'main'"

Could someone tell me what this means? /usr/lib/i386-linux-gnu/gcc/i686-linux-gnu/4.5.2/../../../crt1.o: In function `_start': (.text+0x18): undefined reference to `main' collect2: ld returned 1 exit status make: *** [program] Error 1 My make file…
zeboidlund
  • 9,731
  • 31
  • 118
  • 180
4
votes
2 answers

ld failed because libselinux has undefined reference to gettid@GLIBC_2.30

I'm trying to build glibc 2.24 from source. The host OS is WSL Ubuntu 20.04, the compiler is gcc 9. The ld utility failed when trying to link the nss module of glibc: /usr/bin/ld:…
Lancern
  • 403
  • 2
  • 9
4
votes
5 answers

Undefined Reference to a function

I'm using Linux and I have the following files: main.c, main.h fileA.c, fileA.h fileB.cpp, fileB.h The function F1() is declared in fileB.h and defined in fileB.cpp. I need to use the function in fileA.c, and so I declared the function as extern…
Rayne
  • 14,247
  • 16
  • 42
  • 59
4
votes
1 answer

"undefined reference to symbol" error when using `ld` to link

I am new to writing programs on Linux. I have a single module program that uses shm_open, ftruncate, mmap, fork, and wait. I compiled this program with gcc -c and then linked it with ld -lrt (librt is needed for shm_open) and I got a strange…
4
votes
1 answer

ICPC: "identifier "_Node_allocator" is undefined" when compiling C++ file using std::map with icpc

I am trying to compile the following code: #include int main() { std::map test; return 0; } using the following command: icpc -I /usr/include/x86_64-linux-gnu/c++/8 main.cpp -o test I get the following…
AndyMN
  • 61
  • 3
4
votes
1 answer

Catch2 - undefined reference to

I'm testing my project using Catch2 as library. I followed every step in the Catch doc, but when I run the tests I get the following error: CMakeFiles/tests.dir/tests/IntegerIntervalTest.cpp.o: in function…
sentientmachine
  • 347
  • 3
  • 14
4
votes
1 answer

Undefined Reference in CLion

I made a small test project in C++ and in CLion IDE: main.cpp #include "testclass.h" int main() { testclass *test = new testclass(); test->foo(); return 0; } testclass.cpp #include #include "testclass.h" using namespace…
Yhprums
  • 189
  • 1
  • 11
4
votes
1 answer

Undefined reference to std::__sso_string::__sso_string under Centos7 and devtoolset-7

I've got Centos 7 (CentOS Linux release 7.4.1708 (Core)) with installed devtoolset-7 (gcc/g++ 7.2.1) and I'm trying to build application in debug mode using conan and cmake : cmake .. -DCMAKE_BUILD_TYPE=Debug && make Compilation goes fine, but when…
miqelm
  • 354
  • 4
  • 13
4
votes
2 answers

perl xs module writing - Use another function from within same xs file

I'm a beginner in XS and have spent some time looking for this answer on the web with no luck. The problem is that XS changes the name of the function and when it goes to compile, I will get an undefined reference error. For example consider the…
user2074102
4
votes
1 answer

Undefined reference to function with Cmake in Android studio

I try to add C functions to my Java Android App. I already managed to run a basic function Hello World in C. In this file hello.c I call another C function contained in another file (astart.c) which itself calls another function C in another file…
Hippo
  • 91
  • 1
  • 8