Undefined Reference Problem in Eclipse - c++

I am using Eclipse Galileo 3.5 with CDT 6.0
I am having a problem in including the header files located in c:\cs106 ... I searched on google and found that I have to go to Project Properties > C/C++ General > Paths and Symbols and in GNU C++ I have added the path c:\cs106
And eclipse is able to find them now but the other problem I am getting is that when I try to build a simple program which is using a function defined in "simpio.h" located in c:\cs106 and I have already included at the top of my program #include "simpio.h" but it is giving me an error
**** Internal Builder is used for build ****
g++ -IC:\cs106 -O0 -g3 -Wall -c -fmessage-length=0 -osrc\CS106.o ..\src\CS106.cpp
g++ -oCS106.exe src\CS106.o
src\CS106.o: In function `main':
C:/Users/User/workspace/CS106/Debug/../src/CS106.cpp:8: undefined reference to `GetInteger()'
collect2: ld returned 1 exit status
Build error occurred, build is stopped
Time consumed: 986 ms.
I googled and what I get is that I have to to tell the linker for a .lib file that is accompanied with the header files. in my case the provided .lib file is (CS106CPPLib.lib) and I checked with the project file that I got was of VS 2008 and saw that they have added the following statement in the project settings file under
VCLinkerTool:
AdditionalDependencies="c:\cs106\CS106CPPLib.lib winmm.lib"
So I think I have to include this CS106CPPLib.lib winmm.lib in eclipse as well but I am unable to figure out where should I do this. Please if someone can help me I will be really grateful.
If you need any more info please reply me.
Thanks

It looks like a linker error, it has nothing to do with the header. You now need to link the library in eclipse.

you need to define explicitly library's name in your project... in project setting somewhere
if you already done that... that function is not there in library... Probably you need to add another lib file in which function's definition is there...

Related

Problem while linking a static library during compilation in MinGW, why?

I am trying to compile a simple project which uses one of my headers. I am on Windows and I am using MinGW-W64-builds-4.3.5 Suppose the project is called test.cpp and I want to compile it using my headerosmanip which requires also the linking of its created static library libosmanip.lib. The static library has been compiled and created in MSYS2 and then copied into Windows filesystem. If I try to compile with:
g++ -std=c++17 -losmanip .\test.cpp
To search for the system headers and library path I did:
g++ -v test.cpp
and decided to put headers into C:\MinGW\bin\..\lib\gcc\i686-w64-mingw32\8.1.0\include\c++ and the static library into C:\MinGW\lib\gcc\i686-w64-mingw32\8.1.0\.
I got the following error:
C:/MinGW/bin/../lib/gcc/i686-w64-mingw32/8.1.0/../../../../i686-w64-mingw32/bin/ld.exe:
cannot find -losmanip
collect2.exe: error: ld returned 1 exit status
I've tried also by adding the -L option, linking the library path, or editing the LIBRARY_PATH variable ( $Env:LIBRARY_PATH+=";C:/MinGW/bin/../lib/gcc/i686-w64-mingw32/8.1.0/"), but it still doesn't work.
I tried to move the library into the same folder of the test.cpp file and compile, but again the same error occurs.
It's strange because I tried same thing on Ubuntu, MacOS, MSYS2 and Cygwin64 and it works.
Can you help, me please?
I finally solved the issue. The problem was related to the fact the the suffix of my library was .lib. By changing it in .a and rebuilding the library passing the correct static library name to the ar command the problem disappeared.

Why are the headers not found in the Xilinx SDK?

I am following the course "Introduction to Deep Learning with Xilinx SoCs Technical Training Course" for the Ultra96v2 board and reached Lab No. 5.
I am able to follow along until I am supposed to build the project in the SDK.
It fails and tells me errors like these:
15:49:06 **** Incremental Build of configuration Debug for project mnist_file_io ****
make all
Building file: ../src/mnist_file_io.cc
Invoking: ARM v8 Linux g++ compiler
aarch64-linux-gnu-g++ -Wall -O0 -g3 -I/media/user/6b04b610-ff80-4702-a575-b0b1a78fbafb/training/AvnetTTC/DPU/U96AI_student_20200115/U96AI/2018_3/work/lab5/workspace/ExtraIncludes -I/usr/include -c -fmessage-length=0 -MT"src/mnist_file_io.o" --sysroot=YSROOT -MMD -MP -MF"src/mnist_file_io.d" -MT"src/mnist_file_io.o" -o "src/mnist_file_io.o" "../src/mnist_file_io.cc"
In file included from ../src/mnist_file_io.cc:9:0:
/tools/Xilinx/SDK/2018.3/gnu/aarch64/lin/aarch64-linux/aarch64-linux-gnu/include/c++/7.3.1/cmath:45:15: fatal error: math.h: No such file or directory
#include_next <math.h>
^~~~~~~~
compilation terminated.
src/subdir.mk:21: recipe for target 'src/mnist_file_io.o' failed
make: *** [src/mnist_file_io.o] Error 1
It doesnt find the header file, although it is included in the paths which were provided by the tutorial as well as by me. Actually, two additional files haven't been found:
#include <opencv2/opencv.hpp>
#include <dnndk/dnndk.h>
I was able to include them by picking them by hand from the directories where they were in and adding them to an extra directory in which the Xilinx SDK should search for headers.
But this brings up the question: Why aren't they found in the first place? After correct installation and following the instructions in the above mentioned tutorial, shouldn't I be all set up to just build it?
Actually, by using the installer on the Xilinx Download website (Xilinx_SDK_2018.3_1207_2324_Lin64.bin), the SDK didn't start because there were some files missing for the SDK program (eclipse and some other stuff). So it just started once I copied those files from the other installation (Vivado, etc.). Isn't this also supposed to work just out of the box? Reinstalling, etc. didn't work unfortunately.
So I guess one question that crystallizes here is: Is there a possibility to give Eclipse/Xilinx SDK a path to a directory for all required standard header files and it searches in them? Because in some standard headers, they include other headers, which in turn aren't found by the Xilinx SDK. And will that fix my issues?
Funnily enough, when I use the Ctrl+Click action to jump from header to header, all headers are found and it's no problem. It's only in the build process where embedded further headers aren't found anymore. Also, when I change the #include_next to #include, the whole thing starts working again. The same with changing #include <header> to #include "header.h". Then it works. But that can't be the solution, changing every header that throws an error, since it was generated like this for a reason, right?
This is really annoying and disrupts any workflow.
Is there someone who had this problem as well and may help me?
I am using Ubuntu 16.04 and the Ultra96v2 board.
Update
What I've investigated so far with no avail:
https://e2e.ti.com/support/wireless-connectivity/wi-fi-group/wifi/f/wi-fi-forum/993711/cc3235sf-why-is-ccs-eclipse-unable-to-see-the-c-standard-header-files
Eclipse can't find header file, even though include paths are set
Where are the headers of the C++ standard library
https://www.eclipse.org/forums/index.php/t/1088833/
I have included the path for my C++ gcc standard library as a path in which Eclipse/the Xilinx IDE is supposed to search for headers, but the headers inside the files aren't being found.
Update 2
Here you can see where the problem starts. It's really weird, since everything is auto-generated and thus should just work, especially since those are predefined headers and sources, which haven't been altered by me.
Here, you can see that I included the usual standard header location in the inclusion paths, so the files in question should be found.

How can I compile c++ opengl code using Atom?

So I've installed gpp-compiler extension for Atom, I've put glut.h into my MinGW\include\GL directory as well as I've put libglu32.a file into my MinGW\lib directory and also I didn't forget to put glut32.dll,glu32.dll into C:\Windows\System32 and I've also put glu32.dll into C:\Windows\SysWOW64.
This is the compiler configuration I've got:
settings
And that's the compiling error I'm getting:
b:/mingw/bin/../lib/gcc/mingw32/6.3.0/../../../../mingw32/bin/ld.exe: cannot find -lglut32
collect2.exe: error: ld returned 1 exit status
Looking forward to your answers :)
The linker is not able to find the library glut32.a.
You need to add the folder via
-L<folder containing glut32.a>
to your C++ compiler command line options, where you already declared the libs which shall be linked to your application.

Linking errors on library built using cmake

I guess I just made a simple mistake but I'm not getting which..
Anyways I'm working on a library, also I'm using cmake to build the Makefiles for the project: https://github.com/immapoint/NaNO3/blob/master/CMakeLists.txt
Everything works just fine when compiling the library; it builds the following Files:
bin/libNaNO3.dll
lib/libNaNO3.dll.a (I don't like that name as well)
To test the whole thing, I got another project set up, also using cmake. https://github.com/immapoint/NaNO3TestApp/blob/master/CMakeLists.txt
The main file to test the library looks like this:
https://github.com/immapoint/NaNO3TestApp/blob/master/src/main.cpp
But when it comes to compiling the main file, I'm getting following errors:
CMakeFiles/NaNO3TestApp.dir/objects.a(main.cpp.obj):main.cpp:(.text+0xbf): undefined reference to `nano::Event<int>::attach(std::function<void(int)> *)`
CMakeFiles/NaNO3TestApp.dir/objects.a(main.cpp.obj):main.cpp:(.text+0xd3): undefined reference to `nano::Event<int>::notify(int)`
[...]ld.exe: CMakeFiles/NaNO3TestApp.dir/objects.a(main.cpp.obj): bad reloc address 0x8 in section `.rdata'
This error occures whether I'm building the project using make/cmake or compiling the source file directly using
g++ -Wall -pedantic -ansi -std=c++0x main.cpp [-L./lib -I./include] -lNaNO3
So the problem seems not to lie in cmake but in ld.
I'm working with CMake version 2.8 and MinGW containing GCC version 4.7.2.
Additional information:
Compiler output with -fPIC:
This has nothing to do with CMake or the linker. You need to include the definitions for the nano::Event member functions in the header, not in a separate source file, since templates are instantiated at compile time. By the time the linker gets there, it's too late.
For a fuller explanation, see Why should the implementation and the declaration of a template class be in the same header file? and http://www.parashift.com/c++-faq-lite/templates-defn-vs-decl.html

Using library files in Linux

I'm trying to use some of the functions that are in the /lib/libproc-3.2.6.so library in my Ubuntu distribution.
I have downloaded and installed the header files and they are defined in my source files.
Currently, this is all I'm trying to do, just for starters...
proc_t **read_proc = readproctab(0);
But I get the following compiler error:
/tmp/cclqMImG.o: In function `Sysmon::initialise_sysmon()':
sysmon.cpp:(.text+0x494): undefined reference to `readproctab'
collect2: ld returned 1 exit status
I'm aware I'm probably doing some wrong with the command I'm using to compile it, but due to lack of experience I'm not sure what I'm doing wrong. This is the g++ command I'm using to compile my cpp file:
g++ -o sysmon.o sysmon.cpp `pkg-config --libs --cflags gtk+-2.0`
Can someone please give me some pointers as to where I'm going wrong.
You are not linking your executable against libproc (that is a linker error message).
Try adding -lproc to the linker command.
You are not actually linking against the library that you wish to use, you are merely including its header files, therefor, the compiler will complain about undefined references.
You can read up on linking against shared libraries here.
A small suggestion, start using the build tool SCons, it can take care of linking to libraries for you, just add the ones you wish to use in the SConstruct file required by SCons and then you don't have to mess about with compiler specifics. You also gain lots of other good stuff that SCons provide. It's highly recommended.
Ubuntu 17.04
You probably want to use -lprocps instead of -lproc.