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
7
votes
3 answers

"undefined reference to" using 'g++' to compile a C++ program

I can't seem to get the errors to go away. The errors are below. I have looked on Google Search and still I can't figure it out. It is not like I am new to C++, but I have not fooled around with it in a while. The weird thing is it worked with g++…
Zeveso
  • 1,274
  • 3
  • 21
  • 41
7
votes
3 answers

undefined reference error in VScode

I'm testing the how to use extern in C ,so I create three files for main.c, test.c, headfile.h . I want to declare variable and function in headfile.h,define in the test.c ,then print out the variable and call function at the main.c It works…
Ting-Wei Chien
  • 149
  • 1
  • 2
  • 9
7
votes
1 answer

Odd behaviour of final on a virtual function

I've encountered a strange case when the final keyword is added to a virtual function declaration, with its definition on a separate .cpp file. Consider the following example: IClass.hpp class IClass //COM-like base interface { protected: …
bit2shift
  • 656
  • 1
  • 9
  • 17
7
votes
2 answers

In C programming, what is `undefined reference`error, when compiling?

I have this following simple program I am trying to compile in linux ubuntu. Main.c: #include #include "Person.h" int main() { struct Person1 p1 = Person1_Constructor(10, 1000); } Person.c: #include #include…
dimitris93
  • 4,155
  • 11
  • 50
  • 86
7
votes
2 answers

Is there a way to ignore unused undefined references?

Suppose I have two source files — UndefErr.cpp: #include void UndefFunc(); void Func2(){UndefFunc();} void Func1(){printf("Hi\n");} And the main.cpp: void Func1(); int main(){ Func1(); return 0; } As you see in the UndefErr.cpp…
Hi-Angel
  • 4,933
  • 8
  • 63
  • 86
7
votes
3 answers

Undefined references when trying to link Qt app with my static library

I have a static library that I have built with MinGW, I am trying to link to that library from a Qt application. I keep getting linker errors caused by one of the object files in the library. This file actually declares a couple of Boost headers,…
clintsmith
  • 695
  • 6
  • 16
7
votes
1 answer

undefined reference to `boost::chrono::system_clock::now()' - Boost, and cpp-netlib

I come here to ask for a fix to a situation that has been frustrating me. A lot. First of all, I'm on Windows, I use MinGW as a compiler (C++). I've been having some problems with getting a program to work with the use of cpp-netlib and SSL (trying…
toficofi
  • 583
  • 6
  • 24
6
votes
1 answer

linker error with c++ static library which references another library

I'm pretty new to c++ and I'm having a problem debugging a linker error. I'm using wxDev-c++ with the g++ compiler. I've created a static library which I'm linking to a basic project. The library originally contained no references to external…
TheOx
  • 2,208
  • 25
  • 28
6
votes
1 answer

D2 gdc link error - undefined reference to `_D3std6stdint12__ModuleInfoZ`

I'm using https://bitbucket.org/goshawk/gdc/downloads/gcc-4.5.2-tdm-1-gdc-r575-20110723.zip with TDM GCC 4.5.2 in -v2 mode to build a DLL. In one of the modules I do import std.stdint. So I thought I should link against libgphobos2 to fix this but…
szx
  • 6,433
  • 6
  • 46
  • 67
6
votes
5 answers

What is an undefined reference/unresolved external symbol error and how do I fix it in Fortran?

I am trying to build a Fortran program, but I get errors about an undefined reference or an unresolved external symbol. I've seen another question about these errors, but the answers there are mostly specific to C++. What are common causes of these…
jack
  • 1,658
  • 1
  • 7
  • 18
6
votes
3 answers

How to use CMake to link the "numpy/arrayobject.h"

I am doing FRVT 1:1 verification. So I need to use the program provided by FRVT. I have connected to the program I wrote, and completed implementation. But I want to transplant what I wrote in cython step by step in the NullImp Example provided by…
6
votes
1 answer

Adding intrinsics using an LLVM pass

I've added an intrinsic to an input code using an LLVM pass. I'm able to see the intrinsic call, yet I can't figure out how to compile the code to my target architecture (x86_64). I'm running the following command: clang++ $(llvm-config --ldflags…
Rubens
  • 14,478
  • 11
  • 63
  • 92
6
votes
1 answer

Why is this trying to find the destructor twice?

I was trying out the following piece of code: GeneralTemplate.h #ifndef _GENERATEMPLATE_H_ #define _GENERATEMPLATE_H_ #include template class GeneralTemplate { public: GeneralTemplate(); GeneralTemplate(const…
toutnom
  • 244
  • 1
  • 7
6
votes
0 answers

dynamic_cast with dynamically loaded class causes undefined reference

I have a C++ class whose definition is going to be loaded at run-time through dlopen. I can't get it to link though. I get errors saying there is an "undefined reference to typeinfo". The relevant part of the code looks like this: class Interface {…
Elektito
  • 3,863
  • 8
  • 42
  • 72
6
votes
2 answers

MingW static library linking - SFML 2.1

i'm trying to get SFML 2.1 to work with MingW, but it's causing problems. my compile line in the MingW compiler is: g++ -ID:\SFML-2.1\include -LD:\SFML-2.1\lib main.cpp -lsfml-graphics -lsfml-window -lsfml-system i'm trying to link .a files (does…
user3149569
  • 147
  • 1
  • 12