I'm getting "make: ***[diffusionWeightsTest] Error 1" and "recipe for target 'diffusionWeightsTest' failed" errors when trying to build a program in Eclipse's C++ IDE. If I open the makefile, the following code block is implicated with the error (specifically, the error is on #echo 'Building target: $#'):
diffusionWeightsTest: $(OBJS) $(USER_OBJS)
#echo 'Building target: $#'
#echo 'Invoking: GCC C++ Linker'
g++ -o "diffusionWeightsTest" $(OBJS) $(USER_OBJS) $(LIBS)
#echo 'Finished building target: $#'
#echo ' '
If I create a new HelloWorld C++ project and build it, it seems to work fine. Beyond linking the GSL libraries, I haven't done anything other than copy in my .C and .H code files (from my Windows machine, where I originally wrote them).
I'd like to do C++ development using Eclipse's IDE and the GSL library on a virtual Ubuntu Linux machine. I installed Oracle's JDK, the GSL library (following the INSTALL guidelines), and Eclipse's latest C++ IDE. In my program's properties, I linked the gsl and gslcblas libraries (right-click project name >> Properties >> C/C++ Build >> Settings >> GCC C++ Linker >> Libraries >> add both gslcblas and gsl to Libraries (-l) ) such that Eclipse seems to recognize those functions in the code.
Any ideas what might be causing this makefile error?
Just figured this out, actually. Apparently, there's a particular order in how you link the GSL libraries to your project. You have to list "gsl" first and then list "gslcblas".
So, to clarify, after you've installed the GSL library (download the package from their website, extracted it, opened the terminal inside the GSL folder, ./configure, make, sudo make install), you have to link the gsl and gslcblas libraries to your Eclipse project. Right-click the project name in the Project Explorer in Eclipse >> Properties >> C/C++ Build >> Settings >> GCC C++ Linker >> Libraries >> add both gsl and gslcblas to Libraries (-l).
But you must put gsl first and then gslcblas. The order matters. You'll get the errors above otherwise.
Related
I am attempting to add an existing library to Eclipse. I use a cross compiler for C++ with the Eclipse IDE, installed on a virtual linux debian machine.
The mmapGpio lib is found here.
/mmapGpioBasicRev1.tar.gz has a cpp and an h file with a small demo program.
I have compiled this code without a problem. A .o file is generated. I've archived the file successfully with ar -q libmmapGpio.a mmapgpio.o
I've placed my libmmapGpio.a in ~/.../UserLib directory
I've placed my mmapGpio.h in ~/.../UserInclude
At this point all is OK.
I open a new project that uses the mmapGpio library:
#include "mmapGpio.h"
#include "stdio.h"
int main(void){
mmapGpio rpiGpio; // instantiate an instance of the mmapGpio class
rpiGpio.setPinDir(17,mmapGpio::OUTPUT); // set GPIO17 to output
while(1) {// toggle pin as fast as possible
rpiGpio.writePinHigh(17);
rpiGpio.writePinLow(17);
}
return 0;
}
So cross-compilation is done, but linker say cannot find -llibmapGpio!
I have made declaration in the properties project; C/C++ General
includes path : /home/octopuss/rpi/UserInclude (the mmapGpio.h file)
Library path : /home/octopuss/rpi/UserLib (the libmmapGpio.a file)
Libraries : libmmapGpio
Why do I receive this message?
for detail -> console view
03:16:30 **** Build of configuration Debug for project Gpio1 ****
make all
Building file: ../Gpio1.cpp
Invoking: Cross G++ Compiler
arm-linux-gnueabihf-g++ -I/home/octopuss/rpi/UserInclude -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"Gpio1.d" -MT"Gpio1.d" -o "Gpio1.o" "../Gpio1.cpp"
Finished building: ../Gpio1.cpp
Building target: Gpio1
Invoking: Cross G++ Linker
arm-linux-gnueabihf-g++ -L/home/octopuss/rpi/UserLib -o "Gpio1" ./Gpio1.o -lmmapGpio
/home/octopuss/rpi/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin/../lib/gcc/arm-linux-gnueabihf/4.8.3/../../../../arm-linux-gnueabihf/bin/ld: skipping incompatible /home/octopuss/rpi/UserLib/libmmapGpio.so when searching for -lmmapGpio
/home/octopuss/rpi/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin/../lib/gcc/arm-linux-gnueabihf/4.8.3/../../../../arm-linux-gnueabihf/bin/ld: cannot find -lmmapGpio
collect2: error: ld returned 1 exit status
make: *** [Gpio1] Erreur 1
error :
skipping incompatible /home/.../UserLib/libmmapGpio.so when searching for -lmmapGpio
ld: cannot find -lmmapGpio
"why this message ?"
It's because with your settings, the linker actually looks up for a library file named liblibmmapGpio.a.
"... so crosscompilation is done but linker say "cannot find -llibmapGpio" !
...
- Libraries : libmmapGpio"
You just need to specify the library without the lib prefix in the linker library settings:
mmapGpio
The Eclipse CDT Builder passes this as a -l option to the linker, which automatically extends to search for libmmapGpio.a at the specified additional pathes.
See also this Q&A for more illustrated samples and links:
Problems importing libraries to my c++ project, how to fix this?
I found the problem ... my .so lib wasn't ARM cross compiled so there is a X86 library not compatible whith my ARM Programm.
I solve this to set erm-linuxgnuabihf- prefix and his path to cross setting parameter.
Thanks to TTAVAR PEI and Scott Stensland
enjoy
I am trying to configure Eclipse such that it compiles a shared library in one project and uses it in another.
The problem is, that using the CUDA plugin for Eclipse one can only choose an executable generating project type.
So what I want to do is creating such a project and modify that toolchain such that Eclipse does not execute anything else than nvcc.
As you can see compiling the library is not a problem:
18:27:25 **** Incremental Build of configuration Default for project cudamath ****
make all
Building file: ../test.cu
Invoking: CUDA NVCC Compiler
nvcc --shared -Xcompiler -fPIC -o "cu_test.o" "../test.cu" && \
echo -n 'cu_test.d' ./ > 'cu_test.d' && \
nvcc -M "../test.cu" >> 'cu_test.d'
nvcc warning : The 'compute_10' and 'sm_10' architectures are deprecated, and may be removed in a future release.
nvcc warning : The 'compute_10' and 'sm_10' architectures are deprecated, and may be removed in a future release.
Finished building: ../test.cu
The problem is that Eclipse then calls g++ which is that step of the toolchain I want to cut off:
Building target: cudamath
Invoking: C++ Linker
g++ -L/opt/cuda/lib64 -o "cudamath" ./cu_test.o -lcuda -lcublas -lcudart
/usr/lib/gcc/x86_64-unknown-linux-gnu/4.9.0/../../../../lib/crt1.o: In function `_start':
(.text+0x20): undefined reference to `main'
collect2: error: ld returned 1 exit status
makefile:32: recipe for target 'cudamath' failed
make: *** [cudamath] Error 1
Is there a way I can do this? I've been crawling through my project settings but I can't seem to find what I'm looking for.
Here's what I did using Nsight Eclipse Edition:
File... new CUDA C/C++ project
In the next dialog, select Shared Library...Empty Project, and give the project a name (let's say it is testlib)
Finish that wizard/dialog. A new testlib project is created in the project explorer on the left
In the project explorer on the left, right click on the project name and create a new folder for your source files
Open that folder and create your new source file. For this, I selected a CUDA C/C++ source file using the CUDA bitreverse "template". This creates a new source file with the bitreverse code in it.
change int main() { in your source file to int myfunc(){
save the source file and build the project. A new libtestlib.so is successfully built.
I am trying to setup google test with Eclipse.
This is what I have done so far:
Initial Setup:
Installed CDT on Eclipse Helios.
Downloaded and installed Cygwin.
Downloaded and extracted gtest.
built gtest using cygwin make using the default makefile.
In eclipse:
Created an empty executable c++ project with Cygwin in ToolChain.
Added "[gtest_dir]\include" in C++ Build/Settings/Cygwin C++ Compiler
Added library path as "[gtest_dir]\make" under C++ Build/Settings/Cygwin C++ Linker
Builder was already GNU Make builder
Wrote some example C++ code and built project.
I am facing the following error when I build the project:
Building target: SampleCpp.exe
Invoking: Cygwin C++ Linker
g++ -L/cygdrive/d/gtest-1.7.0/make -o"SampleCpp.exe" ./src/Counter.o ./src/Counter_tests.o -lgtest
/usr/lib/gcc/i686-pc-cygwin/4.8.2/../../../../i686-pc-cygwin/bin/ld: cannot find -lgtest
collect2: error: ld returned 1 exit status
makefile:45: recipe for target 'SampleCpp.exe' failed
What am I missing?
EDIT 1 : [gtest_dir]\make contains two .a files -
gtest.a and gtest_main.a
Also I'm using Eclipse Helios
EDIT 2 :
It worked after I renamed gtest.a to gtest.lib. Is this the expected naming format for a library on Windows?
In project properties for your configuration, under C/C++ Build > Settings > Tool Settings > Cygwin C++ Linker > Miscellaneous > Other Objects, add $GTEST_DIR/make/gtest_main.a.
This makes the linker see gtest_main.a as an archive of object files, rather than a library.
I'm using ubuntu 12.03 and trying to use Symbolicc++ library, it is specified in it's README file that the program using this library should be compiled with command g++ -o program program.cpp -lsymbolicc++. I am wondering how can I enter the -lsymbolicc++ pastfix in the cmakelists.txt file and work on kdevelop?
If you already have program added as an executable to cmakelists.txt a'la;
add_executable(program program.cpp)
then you can just add
target_link_libraries(program symbolicc++)
to add that library when linking.
I'm working on a C++ project with eclipse Indigo + CDT running on linux
It's made of a project for a library, and a project with unit tests for this library.
Obviously the second project depends on the first one.
Both projects use the external builder
But when I modify a header of the first project it does not rebuild the test project. And I can't make it do it... It'll just re-link the second project, even though the header is included in the test project. This is very annoying because I often have working builds while working on the library, then at some point I do a full rebuild and I see a load of errors, on stuff I did 30 minutes ago!
example output of the CDT Global Build Console:
**** Build of configuration Debug for project libxxx ****
make -j all
Building file: ../foo.cpp
Invoking: GCC C++ Compiler
ccache g++ -I"/home/foke/workspaces/cpp/libxxx/include" -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"foo.d" -MT"foo.d" -o "foo.o" "../foo.cpp"
Finished building: ../foo.cpp
Building target: libxxx.a
Invoking: GCC Archiver
ar -r "libxxx.a" ./foo.o ./src/yyy.o ./src/detail/zzz.o
ar: creating libxxx.a
Finished building target: libxxx.a
**** Build Finished ****
**** Build of configuration Debug for project libxxx_tests ****
make -k -j all
Building target: libxxx_tests
Invoking: Cross G++ Linker
g++ -L"/home/foke/workspaces/cpp/libxxx/Debug" -o "libxxx_tests" ./main.o ./aaa.o ./tests/bbb.o ./tests/ccc.o ./tests/ddd.o -lboost_unit_test_framework -lxxx
Finished building target: libxxx_tests
**** Build Finished ****
If you're used to the latest versions of MS Visual Studio then you should clear off a space on your desk and mark it with a giant 'X' - this enevitably where your fist and maybe even your head will bang in frustration when using eclipse/CDT.
Eclipse has it's own dependency mechanism which does almost nothing, but fortunately the CDT module has its own dependency mechanism which tries to do what you want. To set up project dependencies go to:
Project-->Properties-->C/C++ General-->Paths and Symbols-->References
So in your example you would go to the project properties for "libxxx_tests" and select "libxxx.a" as a dependency.
Note that you can also use this page to set the library order, which may be an important step depending on the complexity of your project.