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
45
votes
6 answers

C++ undefined reference to defined function

I cannot figure out why this is not working. I will put up all three of my files and possibly someone can tell me why it is throwing this error. I am using g++ to compile the program. Program: #include #include "h8.h" using namespace…
Mashew
  • 561
  • 1
  • 5
  • 10
42
votes
2 answers

g++ undefined reference although symbol is present in *.so file

I found a number of similar questions (e.g. this, that or this), but none of them helped me solve my problem. I have a *.so file (from the core of gnss-sdr) that, as indicated by: $nm libgnss_system_parameters_dyn.so | c++filt |grep…
Ash
  • 4,611
  • 6
  • 27
  • 41
39
votes
8 answers

C header issue: #include and "undefined reference"

I have three files, main.c, hello_world.c, and hello_world.h. For whatever reason they don't seem to compile nicely, and I really just can't figure out why... Here are my source files. First hello_world.c: #include #include…
user1018501
  • 493
  • 1
  • 4
  • 4
38
votes
4 answers

undefined reference to `__stack_chk_fail'

Getting this error while compiling C++ code: undefined reference to `__stack_chk_fail' Options already tried: added -fno-stack-protector while compiling - did not work, error persists added a dummy implementation of void __stack_chk_fail(void) in…
Akhil
  • 2,269
  • 6
  • 32
  • 39
36
votes
1 answer

"undefined reference" to Virtual Base class destructor

Possible Duplicate: What is an undefined reference/unresolved external symbol error and how do I fix it? I have some experience with Java, and am now doing a C++ course. I wanted to try writing an interface, but I have run into some trouble with…
noctilux
  • 763
  • 1
  • 5
  • 17
34
votes
6 answers

Undefined Reference to

When I compile my code for a linked list, I get a bunch of undefined reference errors. The code is below. I have been compiling with both of these statements: g++ test.cpp as well as g++ LinearNode.h LinearNode.cpp LinkedList.h LinkedList.cpp…
tpar44
  • 1,431
  • 4
  • 22
  • 35
30
votes
4 answers

Compiling with Clang using Libc++ undefined references

The first couple are too long to reference. I get this error when I try to compile clang++ -stdlib=libc++ ../main.cc ... with clang and libc++ from the SVN. error: undefined reference to 'typeinfo for char const*' error: undefined reference to…
norcalli
  • 1,215
  • 2
  • 11
  • 22
30
votes
4 answers

C++ templates, undefined reference

I have a function declared like so: template T read(); and defined like so: template T packetreader::read() { offset += sizeof(T); return *(T*)(buf+offset-sizeof(T)); } However, when I try to use it in my main()…
Daniel Sloof
  • 12,568
  • 14
  • 72
  • 106
27
votes
2 answers

Using GCC Undefined Behavior Sanitizer

Today I have read an article about GCC Undefined Behavior Sanitizer (ubsan). However, when I follow steps there (add -fsanitize=undefined to my code), the compiler (GCC 4.9.2 on Ubuntu 15.04) says that some references are not defined: ||=== Build:…
Ilya
  • 728
  • 2
  • 8
  • 22
26
votes
4 answers

Undefined reference to `initscr' Ncurses

I'm trying to compile my project and I use the lib ncurse. And I've got some errors when compiler links files. Here is my flags line in Makefile: -W -Wall -Werror -Wextra -lncurses I've included ncurses.h Some layouts : prompt$> dpkg -S…
BoilingLime
  • 2,207
  • 3
  • 22
  • 37
25
votes
4 answers

getting error in c program "undefined reference to gettid"

This is my thread sub routine... Here, I am creating 4 threads and passing structure as a argument to thread sub routine. I am trying to print thread id with getid() function, I am getting error saying "undefined reference to gettid()". I have…
PravinY
  • 500
  • 1
  • 5
  • 9
24
votes
3 answers

undefined reference to symbol 'pthread_key_delete@@GLIBC_2.2.5

I'm trying to make a file in Ubuntu and when i make i keep getting this error: /usr/bin/ld: ../../gtest-1.7.0/libgtest.a(gtest-all.cc.o): undefined reference to symbol 'pthread_key_delete@@GLIBC_2.2.5' /lib/x86_64-linux-gnu/libpthread.so.0:…
imolital
  • 241
  • 1
  • 2
  • 4
24
votes
3 answers

RapidXML print header has undefined methods

I've been messing with using RapidXML on one of my projects. It was all going so well until I decided to use it for writing out xml. My code is more or less as follows: //attempt to open the file for writing std::ofstream file(fileName.c_str()); if…
Los Frijoles
  • 4,771
  • 5
  • 30
  • 49
23
votes
5 answers

undefined reference to `__gxx_personality_sj0`

With gcc 4.6 when trying to execute this code: #include using namespace std; #include int main() { //Int<> a; long long min = std::numeric_limits::min(); unsigned long long max =…
smallB
  • 16,662
  • 33
  • 107
  • 151
22
votes
1 answer

Pcap functions have "undefined reference"

I'm trying to go through this tutorial: http://www.tcpdump.org/pcap.html Now I have install pcap (code hints and all that is working) using : sudo apt-get install libpcap-dev and so far I have the following code (file name is…
Yahya Uddin
  • 26,997
  • 35
  • 140
  • 231
1
2
3
82 83