How to link to pistache in Eclipse C++ - eclipse

I fail to link the pistache library in Eclipse C++ on my Ubuntu machine. I already make this reference:
Properties > C/C++ Build > Settings > Tool Settings
Under GCC C++ Linker > Libraries > Library search path
Under GCC C++ Compiler > Includes > Include paths
Add /usr/local/include/pistache to each
It throws a bunch of errors like this:
.... undefined reference to `Pistache::Ipv4::any()'
Why does this fail? The autocomplete is able to see the reference when I try rewrite the whole line, but it still errors out.

You have to let the linker use shared libraries and pass the -fpic option to the compiler:
a. First step -shared, see this image
b. Last Step Position Independent Code -fPic, see this image
Update
Another way to solve this is:
a. Add support for pthread to the linker
b.Add pistache to libraries in the linker

Related

How to link Armadillo with Eclipse

I want to use Armadillo with Eclipse. However all the instructions to link Armadillo is given for Visual Studio. Now I followed the instructions outlined in the ReadMe file of the Armadillo library. I added the Armadillo include folder in project(right click)->properties->C/C++ Build->Settings->Cross G++ Compiler->Includes->Inlcude paths(-I) and then I added the libraries folder (The library folder contain lapack and blas .lib and .dll files) in project(right click)->properties->C/C++ Build->Settings->Cross G++ Linker->Libraries->Library search path (-L).
However when I compile the code in the Eclipse I get the error
.....armadillo_bits/lapack_wrapper.hpp:37: undefined reference to `dgetrf_'.
Shouldn't it simply search for .lib files in the library folder and include them during compiling? I would appreciate any help regarding this matter.
Regards,
TM
Linking the Armadillo library to an Eclipse project can be done and you were about to do it ! It's pretty much the same as for any other library.
In the properties of the project :
GCC C++ Compiler -> Includes : add the path to the file armadillo (where namespace arma is declared) to the include search path (option -I). Example : /home/alpha/soft/armadillo-4.400.1/include
GCC C++ Linker -> Libraries : add the path to the file libarmadillo.so... in the library search path (option -L) Example : /home/alpha/soft/armadillo-4.400.1 . Add armadillo, lapack, blas and m as libraries (option -l). m is for math.
Here are the calls to the compiler and the linker as produced by eclipse :
make all
Building file: ../src/armaeclip.cpp
Invoking: GCC C++ Compiler
g++ -I/home/alpha/soft/armadillo-4.100.1/include -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"src/armaeclip.d" -MT"src/armaeclip.d" -o "src/armaeclip.o" "../src/armaeclip.cpp"
Finished building: ../src/armaeclip.cpp
Building target: armaeclip
Invoking: GCC C++ Linker
g++ -L/home/alpha/soft/armadillo-4.100.1 -o "armaeclip" ./src/armaeclip.o -larmadillo -lblas -lm -llapack
Finished building target: armaeclip
**** Build Finished ****
As you run the code, you might get something like :
error: det(): use of ATLAS or LAPACK needs to be enabled
terminate called after throwing an instance of 'std::logic_error'
what(): det(): use of ATLAS or LAPACK needs to be enabled
Abandon (core dumped)
To avoid this problem, follow the advise of the faq of Armadillo : uncomment #define ARMA_USE_LAPACK in file /home/alpha/soft/armadillo-4.100.1/include/config.hpp and rebuild your project.
You can also create GNU Autotools projects and add following line:
bin_PROGRAMS=armadillo_example
armadillo_example_SOURCES=armadillo_example.cpp
armadillo_example_LDADD=-larmadillo
To Makefile.am file where your source code exist.
If you don't require optimized BLAS libraries, you can use the BLAS and LAPACK libraries that come with Armadillo.
Project properties > C/C++ Build > Settings > GCC C++ Compiler >
Includes > Include paths (-l): C:\armadillo-x.xxx.x\include
Then in Environment Variables > System variables, modify the Path
variable and add: C:\armadillo-x.xxx.x\examples\lib_win64\
Project properties > C/C++ General > Paths and Symbols > Libraries:
blas_win64_MT and lapack_win64_MT (it is important to add them
this way, with no path or .lib/.dll)
Then in Environment Variables > System variables, modify the Path
variable and add: C:\armadillo-x.xxx.x\examples\lib_win64\
And your Armadillo library in Eclipse is good to go.
I've used Eclipse 4.14.0 and Armadillo 9.850.1.

Programming Arduino with avrdude within Eclipse- cannot find -l/usr/avr

I am trying to program the Arudino Nano from Eclipse. It has the same processor as the Uno (Atmega328p). I have had this working before with the Uno, but have since gotten a new hard drive and had to reinstall/reconfigure everything. I am running Fedora 19 with Eclipse Kepler. I am getting an error in the build process that I don't even know where to start looking to solve, and Google hasn't been much help...
Here is the error:
make all
Building target: Arduino_Template.elf
Invoking: AVR C Linker
avr-gcc -Wl,-Map,Arduino_Template.map -mmcu=atmega328p -o "Arduino_Template.elf" ./Analog.o -l/usr/avr
/usr/lib/gcc/avr/4.8.2/../../../../avr/bin/ld: cannot find -l/usr/avr
collect2: error: ld returned 1 exit status
make: *** [Arduino_Template.elf] Error 1
17:29:38 Build Finished (took 124ms)
Has anyone encountered this before? Or does anyone have any suggestions?
Thanks.
The problem could be described like this:
First, the library should be specified only by its name and without the "lib" prefix and the ".a" suffix. The linker (this is where you get the error) will look for the library within the specified in the project paths and will add whatever is necessary to the file library name. So if the library you need is named mystuff it will look for a file named libmystuff.a.
In your case this is specified by the -l/usr/avr which I think could be misconfiguration or you did not copy/paste the entire error output. With the '-l' option you specify the name only, not the entire path to the file.
Second, the path should be specified, in the project configuration, where to look for the libraries, otherwise the linker will look for the library files only within your own project only. Often libraries are part of another project - so you need to adjust the project configuration accordingly.
I had similar problem and this is how I solved it ...
Go to menu Project/Properties. On left - choose "C/C++ Build". On right - choose the tab "Tool Settings". On the tree view choose "AVR C Linker" then "Libraries" sub-item. You are where you may need to make changes.
The list of "Libraries" is where you add libraries names, such as mystuff.
The Libraries Path is where you specify the paths to the libraries. This may look like this: "${workspace_loc:/mystuff/Release}"
The result of this is that the linker will look for this file: /mystuff/Release/libmystuff.a under you workspace root folder.

Threads in Eclipse AND c++11

My goal has been to create multi-threading programs, and I can not even get a simple thread
to execute ON ECLIPSE CDT. my Tools:
ECLIPSE 3.8.1 CDT
Ubuntu 13.10
I have noticed very similar issues regarding mine. I have tried those other solutions but I could not get them to work for me.
When I type the code in Eclipse CDT, Eclipse does not 'resolve' the symbols 'thread', however, It can find the header file 'thread'. 'Mutex' also does not resolve. Furthermore, after building, I run the program, eclipse returns :
"terminate called after throwing an instance of 'std::system_error'
what(): Enable multithreading to use std::thread: Operation not permitted"
Some additional notes:
I can compile and execute the code in the terminal using:
'clang++ c.cpp -pthread -std=c++11'
but...
'g++ c.cpp -pthread -std=c++11' compiles and
produces the same error as quoted above. So it looks like it's a compiler issue. I did
start to write the code in a new project within Eclipse CDT with the clang++ compiler and now that gives the same non-resolved 'thread' and produces the error as quoted above. So now I think I have some wrong settings, paths or flags set in Eclipse.
include <iostream>
include <thread>
using namespace std;
void p1(){
cout<<"process 1 is processing"<<endl;
}
int main() {
thread t1(&p1);
cout<<"Hello from main()"<<endl;
t1.join();
return 0;
}
I have been struggling with the very same issue and I finally resolved it. Here is what I did:
1) Add -std=c++11 for c++ build. To do that right-click your project, select properties and then: C/C++ Build -> Settings -> GCC C++ Compiler -> Miscellaneous(last option)
In other flags append -std=c++11. My Other flags now looks like: -c -fmessage-length=0 -std=c++11 but yours may be a bit different.
2) Add some linker options. In the same view(C/C++ Build -> Settings) as above select the GCC C++ Linker option and from there go to Miscellaneous(second to last option). Add the following Linker flags(the field was empty for me): -Wl,--no-as-needed -pthread. Hit apply.
3) Add a macro. Again from the project properties menu(project->right click->properties). Navigate to C/C++ General -> Paths and symbols -> Symbols. Select GNU C++. Add a symbol with the name __GXX_EXPERIMENTAL_CXX0X__ and no value. Again hit apply.
4) Navigate to C/C++ General -> Preprocessor Include paths.. Select the providers tab. In this tab leave only the following two options checked: CDT GCC Built-in Compiler Settings and CDT Managed Build Setting Entries. Select CDT GCC Built-in Compiler Settings uncheck the checkbox Share setting entries between projects(global provider) and now the text box labeled Command to get compiler specs should be enabled. In this text box append the good old -std=c++11. The text now looks like this for me ${COMMAND} -E -P -v -dD ${INPUTS} -std=c++11. Hit apply one last time.
5) Rebuild the index for the project. To do that right click the project->Index->Rebuild
Following these steps I was able to compile a c++11 multithreaded program, execute it and also Eclipse CDT did not report any errors and was helpful with the autocompletion. Unfortunately this setting has to be done separately for Release and Debug(or at least I have not found a way to share it). Hope this helps.

NO GCOV DATA FOUND

I am using Eclipse Juno with GCC compiler for C code. I am trying to use gcno plugin to get code coverage.
of course I added -ftest-coverage -fprofile-arcs to the compiler and the linker flags.
But, when I click on profiling tools for code coverage I get the error in the image below:
"Recompile at least one of your C/C++ source files with the
"-fprofile-arcs" and "-ftest-coverage" options and link your
executable with "-lgcov". If you compile and link in a single gcc
call, you can use the gcc "--coverage" option. "
Please I need help with this error.
In order to use the gcov code coverage results you must not only compile with the compiler and linker flags you mentions, but you must also either run a unit test or run your program to gather the data. Gcov gathers the data as the points in your code are reached. If you do not run the program you will not generate any data.

Issues with g++ and Eclipse on Linux - unresolved symbols

I am running Ubuntu 64bit version, and downloaded the latest 64bit Eclipse.
Installed g++ along with build-essential. Tested g++ to make sure it works from terminal, and it works fine.
alex#ubuntu:~/Desktop$ g++ test.cpp -o test
alex#ubuntu:~/Desktop$ ./test
Hello World!alex#ubuntu:~/Desktop$
However, trying to build simple C++ Hello Word project(one of the default projects that comes with Eclipse), I am getting error.
Description Resource Path Location Type
Program "g++" not found in PATH Preferences, C++/Build/Settings/Discovery, [CDT GCC Builtin Compiler Settings] options C/C++ Scanner Discovery Problem
I have added Environment variable named g++ with value /usr/bin/g++ and the above error went away, however, now I am getting unresolved errors, though project compiles and in the Console shows !!!Hello World!!!
Description Resource Path Location Type
Symbol 'endl' could not be resolved test_hello.cpp /test_hello/src line 13 Semantic Error
Symbol 'cout' could not be resolved test_hello.cpp /test_hello/src line 13 Semantic Error
Symbol 'std' could not be resolved test_hello.cpp /test_hello/src line 10 Semantic Error
Have I correctly entered Environmental variable ?? How can I get fix the "unresolved" error ?? Thanks !
When compiling there are two important things to consider:
1.) Is my path up-to-date with executables?
2.) Is my library path correct?
It appears you satisfy 1.) but not 2.)
The unresolved symbol error means that Eclipse cannot find your library via LD_LIBRARY_PATH or some other medium. It's attempting to locate the standard compiled C++ library.
How did you install g++?
Kindly do this and post the results:
Project > Properties > C/C++ Build > Environment
If everything there appears nominal, you can try
/sbin/ldconfig
which should hopefully re-parse your system library paths and might update your environment.