undefined-reference

“undefined reference” error in a very very simple c++ program

混江龙づ霸主 提交于 2019-12-01 12:45:36
I have a simple program, which I copied exactly from the example in http://www.learncpp.com/cpp-tutorial/19-header-files/ because I'm learning how to make c++ programs with multiple files. The program compiles but when building, the following error appears: /tmp/ccm92rdR.o: In function main: main.cpp:(.text+0x1a): undefined reference to `add(int, int)' collect2: ld returned 1 exit status Here's the code: main.cpp #include <iostream> #include "add.h" // this brings in the declaration for add() int main() { using namespace std; cout << "The sum of 3 and 4 is " << add(3, 4) << endl; return 0; }

undefined reference to `__gxx_personality_v0' with gcc [duplicate]

折月煮酒 提交于 2019-12-01 12:39:38
Possible Duplicate: What is __gxx_personality_v0 for? I've seen this question circulating around here in the context of compiling C++ code. However I am to compile a pure C code and keep on getting this error. I am forbidden to use "-lstdc++" as a workaround to this gcc problem. How to change my code to get it working and why is this error popping out? My simplified code: //this is main.cpp #include <stdio.h> int main() { char ch[3]; ch[0] = getc(stdin); ch[1] = getc(stdin); ch[2] = '\0'; printf("%s\n", ch); return 0; } My compile command is: gcc main.cpp Use either g++ - since your file is

undefined reference to `__gxx_personality_v0' with gcc [duplicate]

假如想象 提交于 2019-12-01 09:47:19
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: What is __gxx_personality_v0 for? I've seen this question circulating around here in the context of compiling C++ code. However I am to compile a pure C code and keep on getting this error. I am forbidden to use "-lstdc++" as a workaround to this gcc problem. How to change my code to get it working and why is this error popping out? My simplified code: //this is main.cpp #include <stdio.h> int main() { char ch[3

“undefined reference” error in a very very simple c++ program

旧时模样 提交于 2019-12-01 09:47:15
问题 I have a simple program, which I copied exactly from the example in http://www.learncpp.com/cpp-tutorial/19-header-files/ because I'm learning how to make c++ programs with multiple files. The program compiles but when building, the following error appears: /tmp/ccm92rdR.o: In function main: main.cpp:(.text+0x1a): undefined reference to `add(int, int)' collect2: ld returned 1 exit status Here's the code: main.cpp #include <iostream> #include "add.h" // this brings in the declaration for add()

Getting undefined reference to std::thread::_M_start_thread

爱⌒轻易说出口 提交于 2019-12-01 09:23:18
I'm building an app that uses a 3rd party lib (Box2D-MT) which I build from sources. When linking, I get this undefined reference error: b2Threading.cpp:(.text._ZNSt6threadC2IM12b2ThreadPoolFviEJPS1_iEEEOT_DpOT0_[_ZNSt6threadC5IM12b2ThreadPoolFviEJPS1_iEEEOT_DpOT0_]+0xa4): undefined reference to 'std::thread::_M_start_thread(std::shared_ptr<std::thread::_Impl_base>, void (*)())' I am building with g++ and link with -lBox2D -lpthread -lrt -ldl -lstdc++ also, I am compiling with -std=c++11 looking into libstdc++.a I can see a similar this symbol exists (it's "T"): nm -C /usr/lib/gcc/x86_64-linux

c++ linker error: undefined references only on optimized build

廉价感情. 提交于 2019-12-01 09:21:50
I'm getting an undefined references linker error only when linking optimized objects files, not when linking unoptimized object files. I don't understand what the problem is or could be. Here is my unoptimized build: Building file: ../COMPASS.cpp Invoking: GCC C++ Compiler g++ -O0 -g3 -pg -Wall -c -fmessage-length=0 -Wno-sign-compare -fopenmp -MMD -MP -MF"COMPASS.d" -MT"COMPASS.d" -o"COMPASS.o" "../COMPASS.cpp" Finished building: ../COMPASS.cpp Building file: ../PSA.cpp Invoking: GCC C++ Compiler g++ -O0 -g3 -pg -Wall -c -fmessage-length=0 -Wno-sign-compare -fopenmp -MMD -MP -MF"PSA.d" -MT"PSA

.dll Plugin that uses functions defined in the main executable

人走茶凉 提交于 2019-12-01 06:14:50
I have a Main executable that loads . dll / .so Plugins, which works just fine in Linux but on windows(Visual Studio 2012), it fails with undefined reference errors. The plugin uses functions like session->SendLine("bla") which are defined in the Main executable. (class of session ans methods defined in a .h included in the plugin, but the actual function in a .cpp compiled in main exec). tl;dr: "I need the windows linker to ignore undefined references in plugins, defined in the main executable" What is the best way to "make it work" in windows but keep it compatible with Linux without a

Is there a way to ignore unused undefined references?

点点圈 提交于 2019-12-01 04:48:54
Suppose I have two source files — UndefErr.cpp : #include <cstdio> 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 the Func2() going to trigger an error, for it using the undefined UndefFunc() . However the main function doesn't care about the Func2() ! According to a relevant question I could pass an option --unresolved-symbols=ignore-in-object-files to the linker, but I want a kinda different thing. I need a linker to know if the undefined functions used somewhere, and

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

喜你入骨 提交于 2019-12-01 04:31:51
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, one for use of shared_ptr and the other so I can make a class noncopyable. I believe using this boost functionality is what is causing the issue but I have no idea why. If I comment out the classes in the Qt app that use the class defined in the file, the Qt app links fine. This is the error part of the output: C:\blah\build\windows\mingw\libfoo.a(foo

C++ class template undefined reference to function [duplicate]

白昼怎懂夜的黑 提交于 2019-12-01 04:18:02
This question already has an answer here: undefined reference to template function [duplicate] 2 answers 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 T> class number { public: T x; T y; number (int a, int b){ x=a; y=b;} int add (T&); T greater (); }; #endif number.cpp #include "number.h" template <class T> int number<T>::add (T& rezAdd){ rezAdd = x+y; return 1; } template <class T> T number<T>::greater (){ return x>y? x : y; } And my main