C++; eclipse linker error - c++

So working on getting my eclipse IDE going so I can develop my arduino uno in eclipse.
My C++ is weak so this is probably a nube error on my part.
I have a blink program that looks for an arduino library I compiled from the arduino IDE's library.
My code points to the header file and my code find it fine; meaning I can click on:
#include <arduino.h>
and go view the header
this: "C:/programs/arduino-1.0/hardware/arduino/cores/328p_lib/libuno_library.a"
is a valid path... but I get the following error:
>****** Build of configuration Debug for project project1 ****
>make all
>Building target: project1.elf
>Invoking: AVR C++ Linker
>avr-g++ -Wl,-Map,project1.map,--cref -L"C:\programs\arduino->1.0\hardware\arduino\cores\328p_lib" -mmcu=atmega328p -o "project1.elf" ./code/code1.o >-l"C:/programs/arduino-1.0/hardware/arduino/cores/328p_lib/libuno_library.a"
>c:/programs/winavr/bin/../lib/gcc/avr/4.3.3/../../../../avr/bin/ld.exe: cannot find ->lC:/programs/arduino-1.0/hardware/arduino/cores/328p_lib/libuno_library.a
>make: *** [project1.elf] Error 1
>**** Build Finished ******

Well after wasting 2 days or so of fun time I finally found the problem.
http://sourceforge.net/projects/avr-eclipse/forums/forum/664382/topic/4640554
When adding the static library to the linker you have to remove the lib prefix and the .a suffix. not sure what that is about.

Right click on the project>Click on C/C++ BUild> Settings > GCC C++ Linker> Libraries
Click the first icon Add> Add the library name ( without the .a suffix, the suffix will be added automatically)
This will ensure that the library is added to the project.
If the library is part of another project >Go to GCC C Compiler> directories >Add the directory
This will ensure that the library is there for getting the compilation done.

Related

How to link a C project with a C++ static library(using opencv) in eclipse

I have created a c++ static library in eclipse which is using opencv.It is build fine and I want to include it in another c project in the same workspace.
Trying with
1)I have included library path in properties->c/c++ build->setting ->GCC C compiler ->Includes ->"path of project".
2)properties->c/c++ build->setting ->GCC C Linker-> Libraries ->Liraries(-i)->"Name of Lib"
3).properties->c/c++ build->setting ->GCC C Linker-> Libraries ->Liraries(-i)->"path of Lib"
But,this is not working while running the c project cannot find the static library functions giving error -"UNDEFINED REFERENCE TO THE FUNCTION"
Suggest a way to solve the problem.
Thanks in advance.
Got the answer.
These are the files needed to include
"${workspace_loc:/staticLibrary}"
MSDK/include
/IPP_Legacy/x64/include
Levmar/x64/include
/opencv/lib
opengl/x64/include/GL
Tesseract/x64/include/tesseract
freeGLUT/x64/include/GL
/ffmpeg/x64/include/libavcodec
compilers_and_libraries_2016.3.210/linux/ipp/include
compilers_and_libraries_2016.3.210/linux/mkl/include
compilers_and_libraries_2016.3.210/linux/tbb/include
compilers_and_libraries_2016.3.210/linux/daal/include
After these inclusion I faced a error of
/usr/lib/x86_64-linux-gnu/libstdc++.so.6: error adding symbols: DSO missing from command line
for which I got help from the link
http://i0.wp.com/omtlab.com/wp-content/uploads/2013/07/4.png
now the program is working all fine
Thank you

Adding my method to OpenCV

I want to add new method in OpenCV library. I made my_funct.cpp whose code is as simple as:
#include "precomp.hpp"
#include <stdio.h>
void cv::my_funct(){
printf("%s\n","Hello world!");
}
and I added header CV_EXPORTS_W void my_funct(); to files C:\opencv\build\include\opencv2\imgproc\imgproc.hpp and C:\opencv\sources\modules\imgproc\include\opencv2\imgproc\imgproc.hpp. Then I used CMake to build new binaries for whole library, but when I make a new project in which I use my_funct() I get an error:
The procedure entry point _ZN2cv8my_functEv could not be located in
the dynamic link library path_to_this_project\project.exe.
Other opencv functions work just fine. I'm using mingw32 to compile library and the version of OpenCV is 2.4.9. Can you tell me what am I doing wrong?
This looks like an MinGW run-time error. So going by the assumption that you didn't get any compiler or linker errors while building project.exe, your executable most likely doesn't find the matching .dll to your .dll.a import library (which must have included the my_funct() definition).
I would recommend during developments phase - not talking about the install() scripting - to add a post-build step using add_custom_command() and generator expressions to copy the right DLL next to your project.exe:
add_custom_command(
TARGET project
POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy
"<... path to matching DLL ...>"
"$<TARGET_FILE_DIR:project>"
)
Certainly you could also let CMake find the matching DLL, but before I could go into details there I would need to see your project.exe CMake script.
Maybe also good idea - if you are in the process of extending OpenCV code - would be to use ExternalProject_Add() to include OpenCV into your project.
References
MinGW-w64 - for 32 and 64 bit Windows - Wiki: Procedure entry point OpenProcessToken? could not be located in the dynamic link library kernel32.dll
MinGW "The procedure entry point libiconv could not be located ..."
Getting started with OpenCV 2.4 and MinGW on Windows 7

Eclipse c++, how to add std11?

I have installed:
Eclipse IDE for C/C++ Developers
Version: Mars.1 Release (4.5.1)
And I'm tring to execute a working code (already tested).
So I have done:
File -> New -> C++ Project
Than I click on next, next, finish... so without changing anything.
As it is suggested in http://wiki.eclipse.org/CDT/User/FAQ:
Open Project Properties->C/C++ Build->Settings->Tool Settings->GCC C++ Compiler->Miscellaneous->Other Flags. Put "-std=c++0x" at the end.
Than I did the following:
Open Project Properties->C/C++ Build->Settings->Tool Settings->Cross G++ Compiler->Miscellaneous->Other Flags. Put "-std=c++0x" at the end.
I have tried to put -std=c++11 instead of -std=c++0x but nothing changed.
But I still got the following on-the-fly in-the-editor suggestion:
Symbol 'chrono' could not be resolved
The errors are like the following one: "Function 'now' could not be resolved"
No, Tom Mekken, I did not.
How can I set up the paths of the chrono library ?

Error of linking a static lib embedded with Lua on Linux

Update
after using -ldl and link liblua.a in Project 2(console) the compile is okay, but when it runs it crashed with error Segment fault (core dumped) as soon as it runs a Lua function.
Problem Background:
OS: Linux Ubuntu
IDE: CodeBlock
Launguage: C++
2 project:
Project 1: static lib using Lua;
Project 2: console application, using the lib generated by Project 1
Problem description
Project 1 (static lib) is built successfully.
The problem is that when building project 2, it says that those Lua functions in the lib from project 1 are undefined, here is part of the error messages:
g++ -o bin/Release/BattleConsoleCB obj/Release/main.o -s
../BattleConsole/libBattleCore.a
../BattleConsole/libBattleCore.a(DataLoader.o):
In function `boolDataLoader::GetNumber<double>(char const*, double&) [clone .isra.5]':
DataLoader.cpp:(.text+0x13): undefined reference to `lua_settop'
DataLoader.cpp:(.text+0x1e): undefined reference to `lua_getglobal'
DataLoader.cpp:(.text+0x2b): undefined reference to `lua_isnumber'
DataLoader.cpp:(.text+0x3e): undefined reference to `lua_tonumberx'
DataLoader.cpp:(.text+0x51): undefined reference to `lua_settop'
Note that "DataLoader.cpp" is from project 1, which should have been built in the static lib "libBattleCore.a" which should have been embedded with Lua.
How to solve the problem? Thanks for your help.
Additional information:
Project 2 should include: "libBattleCore.h", "main.cpp", libBattleCore.a
Project 1 : CodeBlockbuilding options have included "Lua/install/include" in Compile search directory and "Lua/install/lib" in Link search directory
The same code is successfully built and run on Win with VS2012
If anything else is needed, please inform, I will add it.
I am a green hand on linux and g++. :-(
Thank you
I can't comment without 50 rep. There is no support for anonymous replies. So posting here is all I can do.
It's been a few years, but with g++, I thought it was .o files that you listed on the command line and with libraries you used -L to specify the directory to search and then -lname to include the library. (Where name lacked the leading lib and trailing .a.) E.g. -L../BattleConsole -lBattleCore
Oh, and the ordering of -lfoo -lbar vs -lbar -lfoo is critical, determining which library can use code from the other.
It's not clear that a static library will necessary include code from other libraries. You may need to link (in the right order) against the libraries from project1.
Try "nm". As in nm --demangle libBattleCore.a | grep ... This will let you see what precisely is included in each library. man nm or http://linux.die.net/man/1/nm can help you figure out what the letters stand for. For example, U is Undefined (used by not provided). T is defined in the text (code) segment. W and V are weakly-defined. Etc.

Not found OpenCV libraries using NDK + Cygwin

I'm doing an application for Android using NDK. This is the code received when I compile de C++ code:
Compile++ thumb : pfc_paquete_libreria_PFClib <= pfc_paquete_libreria_PFClib.cpp
In file included from jni/opencv2/core/core.hpp:4342,
from jni/pfc_paquete_libreria_PFClib.cpp:5:
jni/opencv2/core/operations.hpp:62:33: error: ext/atomicity.h: No such file or directory
I found "atomicity.h" in libraries of Cygwin, but GCC compiler don't fount them.
Any idea to solve this problem?
If you know where atomicity.h is, simply add the directory where it resides to the include directories using your compiler's -I switch.