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

Undefined reference: trying to initialize pointer array of objects from different class

The solution from the "duplicated from" question is to initialize the pointer after the class definition but I have found no success doing so. Trying to insert A B::AArray; or A B::AArray = new A[10]; gives me multiple errors including "conflicting…
Potato Salad
  • 37
  • 1
  • 5
-2
votes
2 answers

C++ Undefined reference to destructor and reference to local variable returned

I am trying to create a class template inheriting from another class template, the first being a class containing nothing but pure virtual methods, and the second one being the one that's going to be manipulated. What I am trying to build is a…
-2
votes
1 answer

gnu make C undefined reference to function included in library

UPDATE: Found the problem. It was a bug on my end and had nothing to do with make. I had edited the file to remove the preprocessor conditional and botched it. I am attempting to compile a testing program using a makefile to handle the creation of a…
Duder
  • 1
  • 3
-2
votes
1 answer

different static linking ways of gcc cause different compilation results

I use msgpack-c 1.0.0, when I compile the following program it failed: #include #include int main(void) { /* creates buffer and serializer instance. */ msgpack_sbuffer* buffer = msgpack_sbuffer_new(); …
-2
votes
1 answer

C++ can't call public Method from Class: undefined reference to '::'

I have a a Class (MethodClass.h & MethodClass.cpp files) and a main.cpp In main I'm calling the constructor and then a method. Constructor is working fine but for the method I get the Error: "Test/main.cpp:13: undefined reference to…
Guti_Haz
  • 2,528
  • 2
  • 15
  • 20
-2
votes
2 answers

Undefined refernce static member C++

I'm sick of this, I'm really exhausted. I am new in C++. But I have read a lot about that ,but still doesn't understand what is the correct to implement this. I have just copied all code from this article Signal Handling in C++ BUT it still doesn't…
braohaufngec
  • 31
  • 1
  • 1
  • 8
-2
votes
1 answer

C++ Template, Linker undefined reference despite instantiation?

I tried to make a template class for an implementation of a 3D vector. Relevant snippet of the 2 files (vec3d.h and vec3d.cpp) are here on pastebin. The main.cpp is as follows: #include "vec3d.h" #include using namespace std; int…
Kunal Tyagi
  • 549
  • 4
  • 12
-2
votes
2 answers

Simple C++ undefined reference error during linking while using a class

I've got a simple problem I think. But I am unable to solve it so far as I am new to C++ programming. I have created a new C++ project to make the code as short and simple as possible (because the original code is much much longer) while keeping the…
WillemB
  • 3
  • 3
-2
votes
1 answer

Order of Header files being included in a C++ app

Is there software/tool to see the order in which header files are being included after compilation of a C++ application? I find myself often running into circular dependency issues and seeing the "undefined reference" error message :( UPDATE #1 I am…
code
  • 5,294
  • 16
  • 62
  • 113
-2
votes
2 answers

undefined reference to a user-defined function

I am now implementing 3DES, I got the error like this: The log: Compiling 'ReadTag_new' for 'Arduino Uno PN532.cpp.o:In function PN532::example()' PN532.cpp:undefined reference to des3_set2key_dec' PN532.cpp:undefined reference to…
Bao Doan
  • 87
  • 1
  • 2
  • 13
-2
votes
2 answers

Undefined reference to exception used in another function

i've done a program. Unfortunately when trying to build it i got an error in function: undefined reference to `RzymArabException::RzymArabException(std::string). When i was throwing a simple class like class Rzym{}; there was no errors. But when i…
user3402584
  • 410
  • 4
  • 8
  • 18
-2
votes
2 answers

g++ error: undefined reference while netbeans compiles in linux

Im using NetBeans IDE in linux mint for C++ programming. NetBeans compiles the code just fine but when i try to compile the main.cpp using g++ as in g++ main.cpp i get undefined reference errors: I know there are many questions like this one and…
Varaquilex
  • 3,447
  • 7
  • 40
  • 60
-2
votes
2 answers

C++ error: "undefined reference to cnt(int) collect2: error: ld returned 1 exit status

When I compile this C program, I get an error: In function `main': maxcount.cpp:(.text+0x63): undefined reference to `cnt(int)' collect2: error: ld returned 1 exit status What does it mean? Here is the code: #include using namespace…
kaala
  • 47
  • 2
  • 5
-3
votes
2 answers

When is definition of class' static data member (un/-)necesary

I have a big project and work on refactoring it. Major task is rewrite of logger. New logger is (as far as I can tell) API-compatible with old one, so I believed that after changing header include directory, recompile and relink everything should…
MateuszL
  • 2,751
  • 25
  • 38
-3
votes
2 answers

c-linux-debian undefined reference to function in multi thread program

I got error message about "undefined reference to function". How can i solve this? Error message is in the image. We are trying to make a multi-thread sorting program. First, a series of 800 elements and a random distribution of distributions should…
1 2 3
82
83