Programming :: Undefined Reference To Function While Linking
May 27, 2010
I am trying to add some function to the c++ project (calling function) and the called function are in C. And i am getting error "undefined reference to "Hello(int,int)" " while linking. It is compiling correctly. It is linking to header file mention in the calling function. This header file has definition to the c - called function. Do you thinking having c files into C++ project will be a problem? Should I remove <stdio.h> in c files?
I have created a simple test class - Mortgage, with the class declaration in the .h file and the class's methods defined in the .cpp file. (mortgage.h && mortgage.cpp, respectively) Straight up C++ 101 as far as I can tell. I instantiate the class in the main() function, which is defined in practice.cpp. Using Geany on Ubuntu, both the practice.o and mortgage.o files are created, but then I get a linker error: undefined reference to class::functionName
I get it for each function. If the mortgage.cpp file is foremost in the editor when I click "build", then I get the undefined reference to main() error, if practice.cpp is foremost (where the main() function is) then I get undefined reference to Mortgage::Mortgage(), and all the rest of the functions defined for that class. How do I get the linker to know where my object files are so it will link them in? Or is the problem somewhere else entirely?
I'm trying to create a program from 2 files - main.cpp that contains the main function, and modules.c that contains the definitions of the functions that are called in main(). modules.c only contain function definitions, no main function.
My Makefile is as follows:
I have included "modules.h", which contains all the function declarations, in my main.cpp.
When I try to make using this Makefile, I get the error
If I switch the order of modules.o and main.o in my $(TARGET) line, then I get errors that say "undefined reference to" the functions I have defined in modules.c, in main.cpp.
I'm trying to build a shared library, and am receiving several undefined reference linking errors. Specifically, ffmpeg linked with libx264. I'm aware that this is not an appropriate forum for questions specific to ffmpeg or libx264. In order for one library / application (ffmpeg) to reference another library (libx264), the linker has to know where the referenced library (libx264.so) is located in the file system.
I'm pretty sure the linker knows where libx264.so is, because I receive a different error message when I run ffmpeg's configure script if the linker can't find libx264.so. In general, should running the install target of a make file be preferred over specifying the appropriate paths in the CFLAGS and LDFLAGS environment variables? I've tried both, and it doesn't seem to make a difference in regard to my error which method I choose.
How exactly is a library referenced? My error messages are /root/ffmpeg/libavcodec/libavcodec.so: undefined reference to `d26' /root/ffmpeg/libavcodec/libavcodec.so: undefined reference to `d22' /root/ffmpeg/libavcodec/libavcodec.so: undefined reference to `d2' /root/ffmpeg/libavcodec/libavcodec.so: undefined reference to `d20' /root/ffmpeg/libavcodec/libavcodec.so: undefined reference to `d24' /root/ffmpeg/libavcodec/libavcodec.so: undefined reference to `d0' /root/ffmpeg/libavcodec/libavcodec.so: undefined reference to `q1'
If I can find out what library 'd26', 'd22', etc. are declared in, I should be able to resolve the undefined references. What exactly are 'd26', 'd22', etc.? Are these functions, classes, or something else? How can I find out what functions / classes are defined in a particular library?
I am facing the problem of calling cfitsio library from C program in linux. when i am givingthe option "gcc -o CreateLevel1DataFitsFile CreateLevel1DataFitsFile.c -lm -lcfitsio "i am getting following error
/usr/lib/../lib/gcc/i386-redhat-linux/3.4.4/../../../libcfitsio.a(getcolj.o)(.text+0x7065):/backup/Astrosat/learning/cfits/cfitsio/getcolj.c:3098: more undefined references to `__xtoll' follow
I am using Centos 5.4 with gcc v4.1.2. If I take a bunch of .o files and I then link with my main.o to form an executable then this links and executes just fine. If however, I try to create an archive file (.a) using 'ar rus xxx.o yyy.o etc' and then try to link the resulting .a with my main.o then I get 'undefined symbol' linker errors and I don't understand why.
Do you have any ideas why does wxHyperlinkCtrl doesn't work on Linux?It has an error which says..."/usr/include/wx-2.8/wx/gdicmn.h:215: undefined reference to 'vtable for wxHyperlinkCtrl'"Do I have to include a certain library so that it will work in Linux? I try to compile it in windows and its succesful.'m having a problem on Linux guysinitialize the wxHyperlinkCtrl like this... wxHyperlinkCtrl* hyperlink1 = new wxHyperlinkCtrl();and included #include <wx/hyperlink.h> Is there something missing on it?... I already had tried supplying parameters on the constructor but same thing it gives me an error
I'm writing a binary search tree class to insert records and I'm stuck on the following error:
Code: /usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../lib64/crt1.o: In function `_start': (.text+0x20): undefined reference to `main' collect2: ld returned 1 exit status Here is the code for my class:
I really don't know how to approach this, I thought that everything was working fine but I have no idea what is wrong. Also, for clarification, main() is in a different .cpp file that #includes "tree.h"
I am trying to install NOX which is a openflow controller and it needs Xerces-C++ this. I installed it successfully on the Debian. The output of the xerces after running the "make install" command is as follows which shows that is successfully installed on the machine.
You can see the link commands I'm using, and the lib and include path are both valid. I tried replacing -lmysqld with -lmysqlclient but this did not help. I'm using Debian and MySQL, libmysqld-dev and libmysqlclient-dev are all installed.
I am creating two shared libs that i intend to be dynamically linkable in C and C++, cross platform Linux/Windows/Mac. As a basic sketch, true for both libs, the lib code is in several .c/.cpp and .h files. For now, I'll talk about the part that I am actively working on, a lib named Discover, i.e. libdiscover.so.1.0. First, everything is in a namespace, RemKon_Discover.
The main Discover.cpp defines the methods for the Discover class (declared in Discover.h) and has extern "C' routines that can return pointers to my main c++ object. The call to GetLibraryMainPointer() creates a Discover class object, theMainObject (ok, I win a prize for dumb names) and returns the (non-mangled) pointer to the caller over in my test program. The Discover class itself is declared extern "c" and the tester program #includes "Discover.h".
In the test program, dlopen() correctly opens the lib and dlsym() gets the pointer to theMainObject. However, when I use that pointer in the tester program to access a method (aDiscoverObject->hello(), e.g.) I get compile time errors saying that Discover::hello() in an undefined reference. My makefile is attached.
I am writing a function(in C language in Linux) to initialize an array of a structure from a mysql table by calling a function by reference but I have a problem with call this function by reference . this is my program:PHP Code:
I am slowly getting accustomed with linux issues and its different programming compilation stuffs. and i must say am truly liking it. Now i am facing this typical error , "undefined reference to `clock_gettime'" while i am compiling a code, which is not mine as it required to install a simulator. Now i have read about this type for the last 2 days and i have included "-lrt" in the make file and included <time.h> in the header files which was missing but still i am getting that error.
Now matter how many times i run the make file with the required changes its still giving me this error, which i have comprehended as mainly linking problem rather than a compilation issue.