How can CDT project be compilable by itself, but not compilable as linked folder? - c++

I have C++ project which is compilable (the project is leptonica). It consists of configure script and then compiles with make.
If I import this project into Eclipse CDT, then it also compiles (with autotools toolchain).
But then, if I create empty CDT static library project, and refer project above from within it, then it becomes not compilable. It tries to compile referred project and produces some bad errors like include file not found and so on.
My question is how it can be?
UPDATE
Sorry, I am referring the project by linking a folder.
I.e. Project Properties -> C/C++ General -> Paths and Symbols -> Source Location -> Link Folder -> Link to folder in the file system
When linking, a message
Location 'mylocation' may overlap another resource. This can cause unexpected side-effects.
appears.
UPDATE 2
Actual error is
Building file: <mypath>/leptonica-1.69/src/freetype.c
Invoking: GCC C Compiler
gcc -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"leptonica-1.69/src/freetype.d" -MT"leptonica-1.69/src/freetype.d" -o "leptonica-1.69/src/freetype.o" "<mypath>/leptonica-1.69/src/freetype.c"
In file included from <mypath>/leptonica-1.69/src/freetype.c:31:0:
/usr/include/ft2build.h:56:38: fatal error: freetype/config/ftheader.h: No such file or directory
compilation terminated.
make: *** [leptonica-1.69/src/freetype.o] Error 1
I.e. it can't find file which it finds successfully if compiled standalone.

Related

cannot compile c++ programs with input and output in eclipse

Whenever I try to build C++ programs that involve I/O, I get errors in Eclipse.
02:19:02 **** Incremental Build of configuration Debug for project SecondProject ****
make all
Building target: SecondProject
Invoking: GCC C++ Linker
g++ -o "SecondProject"
g++: fatal error: no input files
makefile:45: recipe for target 'SecondProject' failed
compilation terminated.
make: *** [SecondProject] Error 1
It compiles just fine for other C++ programs that don't require user input.
However, I can compile just fine when I use the command line without an issue. Why is this happening? Is there a fix for it?
The compiler is attempting to compile SecondProject with no source files. Which is why you observed this:
g++ -o "SecondProject"
g++: fatal error: no input files
Troubleshoot
Verify your project properties in
Properties > C/C++ General > Paths and Symbols
Check that your Source Location and Include paths are setup correctly. If your paths are correct, you should see something like when you build again:
g++ -o "SecondProject" ./<your src folder>/<something>.o ...
Otherwise, create a fresh new C/C++ Project and add the sources again.

Add C++ Library to eclipse C++ Project

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

Eclipse: Edit toolchain (remove build step to create a shared library for CUDA)

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.

How to use external .h and .o files in current project with Eclipse CDT

I was given three files to test my project: Test1.cpp SignalMasker.h and SignalMasker.o when Test1.cpp includes the SignalMasker.h file and files from my project. Putting both in the source folder returns undefined references such as:
error: undefined reference to 'SignalMasker::~SignalMasker()'
I tried to use the project preferences and add the .o file to it. Under GCC C++ Linker-> Miscellaneous -> other objects. When selecting a file it inserted a new record as:
"${workspace_loc:/${ProjName}/source/SignalMasker.o}"
Building it didn't seem to resolve the issue so I added to the Linker flags the -l flag and got:
Invoking: GCC C++ Linker
g++ -l -o "uthreads" ./source/Scheduler.o ./source/SchedulerStarter.o ./source/Test1.o ./source/Thread.o ./source/main.o ./source/uthreads.o /home/tom/workspace/uthreads/source/SignalMasker.o
g++: error: uthreads: No such file or directory
make: *** [uthreads] Error 1
So I went back to other objects and replaced the automatic generated variable to:
./source/SignalMasker.o
And building gave me:
make: *** No rule to make target `source/SignalMasker.o', needed by `uthreads'. Stop.
These are all solutions I've found in SO and none seem to work including making a library and trying to include it. Please help.
EDIT: uthreads is also the name of the project.

Building shared library with Eclipse CDT directly

I would like to move the building of my C++ project completely to Eclipse CDT, however I am facing some configuration problems. Here is my old g++ compiler call:
g++ -I/home/lib/tinyxml
-I/usr/lib/jvm/java-6-openjdk/include
-L/usr/local/lib -L/home/konrad/tinyxml
-lboost_system
-lboost_thread
-lboost_regex
-fPIC
-shared
-o libagent.so
agent.cpp AgentSocket.cpp ThreadInfo.cpp
/home/lib/tinyxml/tinyxml.cpp
/home/lib/tinyxml/tinyxmlerror.cpp
/home/lib/tinyxml/tinyxmlparser.cpp
/home/lib/tinyxml/tinystr.cpp
When creating the project I choose Shared Library > Emtpy Project
Here are my problems:
The Eclipse CDT generates the makefile in a way, it first compiles every .cpp file and then recompile it to the shared library. This let's me face one or more issues. I would like to jump this step and run it in the same way I did in the console.
I cannot configure -L and -l options into the C++ building configuration, as Eclipse CDT offers these option only for the C++ linking part, but not for the C++ compiler part, but I need them already there, as the project doesn't compile without errors.
That's not a problem, but actually how makefiles usually are constructed. This way, if you change one source file, you don't have to recompile all other source files, but only the one that has changed. It minimizes recompilation time.
That shouldn't be a problem, because they are options that are only used during linking. Compilation of source files into object files shouldn't depend on external libraries.