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

Undefined reference to 'dlsym' and 'dlopen'

I am compiling using arm-linux-gnueabi-g++ version 4.7.3. I have the arm-linux-gnueabi libraries installed at location: /usr/arm-linux-gnueabi/lib, it contains libdl.a, libdl.so, libdl.so.2, and libdl-2.19.so. libdl.so links to libdl.so.2 which…
Fred
  • 1,054
  • 1
  • 12
  • 32
9
votes
1 answer

Linking libavcodec and libavformat: Undefined references

I am trying to compile a project I am working on that uses ffmpeg libraries. The project is written in C. The header files are appropriately included in the source code. In particular, it seems to be using libavcodec and libavformat, and these…
lite-whowantstoknow
  • 799
  • 3
  • 9
  • 18
9
votes
3 answers

C++ class template undefined reference to function

I keep getting undefined reference when i call the two functions from my template class "add" and "greater" in my main function. So, i have: number.h #ifndef NUMBER_H #define NUMBER_H template class number { public: T x; T y; …
MihaiGrad
  • 105
  • 1
  • 1
  • 5
9
votes
2 answers

undefined reference error for linking CUDA static or shared library with gcc

gcc and CUDA question Hi, I have compiled a CUDA shared library but can't link it with the main program that uses it. I am compiling the main program with gcc. The code: simplemain.c #include #include void…
Bibrak
  • 544
  • 4
  • 20
9
votes
3 answers

Undefined reference to CryptoPP::AlignedAllocate(unsigned int)

I am using crypto++ in c++ linux. Here is my simple code: #include #include #include #include "crypto++/cryptlib.h" #include "crypto++/modes.h" #include "crypto++/filters.h" #include "crypto++/aes.h" #include…
user1533464
  • 163
  • 1
  • 5
8
votes
1 answer

linking pthread library issue

Am facing a problem that may be slightly complicated to explain and understand as giving the entire picture would be too big and difficult. Please excuse me for it. Consider the following Makefile: all: clients.so simulator backup …
Lipika Deka
  • 3,774
  • 6
  • 43
  • 56
8
votes
3 answers

OpenMp Task: can't pass argument by reference

g++ -fopenmp main.cpp complains about undefined reference to std::vector. How to fix this? I have installed the libomp-dev package on Ubuntu. main.cpp #include #include template T…
hamster on wheels
  • 2,771
  • 17
  • 50
8
votes
7 answers

gcc wont compile and run MySQL C libraries

#include #include int main(int argc, char **argv) { printf("MySQL client version: %s\n", mysql_get_client_info()); } ~$ gcc -o mysql-test MySQL-Test.c im trying to execute this test program from terminal but get the…
JB87
  • 317
  • 3
  • 5
  • 14
8
votes
2 answers

Undefined symbols error when using a header file

I'm getting the following error and can't for the life of me figure out what I'm doing wrong. $ gcc main.c -o main Undefined symbols: "_wtf", referenced from: _main in ccu2Qr2V.o ld: symbol(s) not found collect2: ld returned 1 exit…
Chris Cummings
  • 2,007
  • 5
  • 25
  • 39
8
votes
1 answer

Use libcurl undefined reference to 'curl_easy_init'

use libcurl to writer some test code. when try to compile, it says undefined reference. already use -lcurl or -L compile option. root@ubuntu:~/work/test/curlTest# curl-config --libs -L/usr/lib/x86_64-linux-gnu…
hkx_1030
  • 153
  • 1
  • 3
  • 7
8
votes
5 answers

C++: Undefined reference to instance in Singleton class

I'm currently trying to implement a factory as a singleton. I practically used the textbook example of the Singleton pattern. Here's the .h file: namespace oxygen{ class ImpFactory{ public: static boost::shared_ptr
aheld
  • 313
  • 1
  • 5
  • 11
8
votes
1 answer

clang++ 3.2 linker not finding C++ stdlib

I've installed clang 3.2 on my Ubuntu 13.04 machine, and have compiled and built libc++, and everything is in place. However, when I try to link my (really simple) code, the linker reports that references to std::cout etc. are undefined. If anyone…
biot023
  • 163
  • 2
  • 9
8
votes
3 answers

C++: Undefined reference to function in namespace

Here I am, trying to figure out what's wrong with my code without success :( I'm writing a resampler but I guess that's of no interest at all, I'm just trying yo make this stupid warning go away. Anyway, here's my code: ddc.hpp #ifndef…
mr_hyde
  • 505
  • 1
  • 6
  • 11
8
votes
3 answers

Undefined reference to `typeinfo for class' and undefined reference to `vtable for class'

I'm dealing with inheritance in C++. I wanted to write a program for addition and subtraction of two arrays. Heres my code: #include #include #include using namespace std; class root { protected : int…
Brian Brown
  • 3,873
  • 16
  • 48
  • 79
8
votes
1 answer

Undefined reference to operator >>

I am trying to work on operator overloading, my header file consists of: #ifndef PHONENUMBER_H #define PHONENUMBER_H #include #include using namespace std; class Phonenumber { friend ostream &operator << ( ostream&, const…
Avinash Gopal
  • 101
  • 1
  • 1
  • 5