undefined-reference

Undefined Reference to a function

六眼飞鱼酱① 提交于 2019-11-29 07:57:12
I'm using Linux and I have the following files: main.c, main.h fileA.c, fileA.h fileB.cpp, fileB.h The function F1() is declared in fileB.h and defined in fileB.cpp . I need to use the function in fileA.c , and so I declared the function as extern void F1(); in fileA.c . However, during compilation, I got the error fileA.c: (.text+0x2b7): undefined reference to `F1' What is wrong? Thank you. ETA: Thanks to the answers I've received, I now have the following: In fileA.h, I have #include fileB.h #include main.h #ifdef __cplusplus extern "C" #endif void F1(); In fileA.c, I have #include fileA.h

Undefined reference - despite lib being found by linker

为君一笑 提交于 2019-11-29 07:50:32
问题 I have a trivial program to test for availability of python development files: #include<Python.h> int main(){Py_Initialize(); Py_Finalize(); } I compile it (with python 2.7 installed) as gcc -I/usr/include/python2.7 -lpython2.7 p.c . It works fine on other machines, except that at mostly-clean chroot of Ubuntu 12.04 (precise) I keep getting /tmp/ccj8Mgjb.o: In function `main': p.c:(.text+0x5): undefined reference to `Py_Initialize' p.c:(.text+0xa): undefined reference to `Py_Finalize'

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

瘦欲@ 提交于 2019-11-29 07:16:23
This question already has an answer here: What does the “undefined reference to varName” in C mean? 6 answers I have this following simple program I am trying to compile in linux ubuntu. Main.c : #include <stdio.h> #include "Person.h" int main() { struct Person1 p1 = Person1_Constructor(10, 1000); } Person.c : #include <stdio.h> #include "Person.h" struct Person1 Person1_Constructor(const int age, const int salary) { struct Person1 p; p.age = age; p.salary = salary; return p; }; Person.h : struct Person1 { int age, salary; }; struct Person1 Person1_Constructor(const int age, const int salary);

OpenCV - undefined reference: SurfFeatureDetector and BruteForceMatcher

拟墨画扇 提交于 2019-11-29 06:11:55
问题 I'm making a program in C++ that uses 2 images to detect SURF Features, compute the matches with a bruteforcematcher and draws it. Here's the code #include <cstdio> #include <string> #include <vector> #include "opencv/cv.h" #include "opencv/highgui.h" #include "opencv2/features2d/features2d.hpp" using namespace cv; using namespace std; int main(int argc, char **argv){ if (argc <3) { cout << "Usage: " << argv[0] << " imageLocation1 imageLocation2" << endl; return -1; } Mat source1 = imread

glfw3 compiling undefined references

别等时光非礼了梦想. 提交于 2019-11-29 02:05:58
I have a problem with compiling my program which uses glfw3 library. I'm getting list of errors of undefined references when trying to compile with make but my classes are compiled into .o files, only final executable file is not created. stdout: g++ -Wall -g -c main.cpp -lGL -lGLU -lglfw3 -lX11 -lXxf86vm -lXrandr -lpthread -lXi g++ -Wall -g -c error.cpp -lGL -lGLU -lglfw3 -lX11 -lXxf86vm -lXrandr -lpthread -lXi g++ -Wall -g -c sWindow.cpp -lGL -lGLU -lglfw3 -lX11 -lXxf86vm -lXrandr -lpthread -lXi g++ -Wall -g -o ecl main.o error.o sWindow.o -lGL -lGLU -lglfw3 -lX11 -lXxf86vm -lXrandr

How to resolve __gcov_init undefined reference issue when linking

人走茶凉 提交于 2019-11-28 22:05:36
问题 I now work on C code coverage study and encountered following issue, GCC version 4.4.6: Added compiler flag CFLAGS = --coverage and linker option LDFLAGS := --coverage or LOCAL_LDLIBS := --coverage and got the error: undefined reference to '__gcov_init'" and "undefined reference to '__gcov_merge_add' Added option LOCAL_LDFLAGS := --coverage , and got link error: libgcov.a(_gcov.o): in function __gcov_set_sampling_rate: undefined reference to '__gcov_sampling_rate' libgcov.a(_gcov.o): in

Compiling with Clang using Libc++ undefined references

让人想犯罪 __ 提交于 2019-11-28 21:10:03
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 '__cxa_allocate_exception' error: undefined reference to '__cxa_throw' /tmp/cc-pbn00y.o:../main.cc:function std::__1::deque<double, std::__1::allocator<double> >::__add_back_capacity(): error: undefined reference to '__cxa_begin_catch' /tmp/cc-pbn00y.o:../main.cc:function std::__1::deque<double, std::__1::allocator<double> >::__add_back_capacity(): error

c++ “ undefined reference to 'Foo::Foo(std::string)' ”

谁说我不能喝 提交于 2019-11-28 14:05:20
I'm not too familiar with c++ and how instantiating objects work, so this is probably a very simple thing to solve. When I compile with g++ I get the error " undefined reference to 'Foo::Foo(std::string)' ". I want to create an instance of the class Foo that has a string parameter in its constructor. Here is the code: Foo.h #include <string> using namespace std; class Foo { public: Foo(string s); private: string id; }; Foo.cpp #include <string> #include "Foo.h" using namespace std; Foo::Foo(string s) { id = s; } main.cpp #include <string> #include "Foo.h" using namespace std; int main() { Foo

C++:Undefined reference to 'FMOD:: X'

…衆ロ難τιáo~ 提交于 2019-11-28 12:55:34
After looking around for various sound API libraries, I have decided to use FMOD for the time being. Problem is that whenever I try to compile one of the code examples, I get the following errors: obj\Release\main.o:main.cpp|| undefined reference to `FMOD::System::getVersion(unsigned int*)@8'| obj\Release\main.o:main.cpp|| undefined reference to `FMOD::System::init(int, unsigned int, void*)@16'| obj\Release\main.o:main.cpp|| undefined reference to `FMOD::System::createSound(char const*, unsigned int, FMOD_CREATESOUNDEXINFO*, FMOD::Sound**)@20'| obj\Release\main.o:main.cpp|| undefined reference

C-callback to function template: explicitly instantiate template

只愿长相守 提交于 2019-11-28 09:53:02
Premise I’m using a C library (from C++) which provides the following interface: void register_callback(void* f, void* data); void invoke_callback(); Problem Now, I need to register a function template as a callback and this is causing me problems. Consider the following code: template <typename T> void my_callback(void* data) { … } int main() { int ft = 42; register_callback(reinterpret_cast<void*>(&my_callback<int>), &ft); invoke_callback(); } This gives me the following linker error (using g++ (GCC) 4.5.1 on OS X but works on most other combinations of compiler version / platform ):