I have the below in a Cmake file:
add_library(stasm STATIC IMPORTED)
set_property(TARGET stasm PROPERTY
IMPORTED_LOCATION /media/Data/sdks/stasm3.1/linux/libstasm.a)
target_link_libraries( StasmOpencvExample ${OpenCV_LIBS} stasm)
I generated the libstasm.a by doing:
How to create a static library with g++? , the first answer, taking all of the .o files from the linux folder and putting it into an archive.
but when i run make on my project i get:
Scanning dependencies of target StasmOpencvExample
[100%] Building CXX object CMakeFiles/StasmOpencvExample.dir/stasm_opencv_example.cpp.o
Linking CXX executable StasmOpencvExample
CMakeFiles/StasmOpencvExample.dir/stasm_opencv_example.cpp.o: In function `main':
stasm_opencv_example.cpp:(.text+0x9a): undefined reference to `AsmSearchDll(int*, int*, char const*, char const*, int, int, int, char const*, char const*)'
collect2: ld returned 1 exit status
has anyone gotten a cmake project to work with stasm on linux before? I also had to remove a n include "windows.h" from stasm_dll.cpp, and other windows specific code that wasn't properly done to allow working on linux.
I have already gotten the linux folder to generate the binaries and they work great, now I just need to incorporate this functionality into my own project..
It seems that the reason was that Stasm was created to make executables on Windows that did Image processing. Stasm DOES NOT act like a library, I'm currently making my own static and shared library that will act like a library that you can use to import into a random project and specify the parameters.
Basically modifiying main.cpp to another class and taking out the testing/unecessary code and get a thin processing version.
Related
Under tools folder caffe library have some tools as single .cpp files
https://github.com/BVLC/caffe/tree/master/tools
I have added my own tool under this folder and can build it via cmake.
The problem that when I have added additional dependency (json lib jsoncpp) build fails at linking phase.
I have put json lib .h, .cpp files under tools/json folder.
My includes:
#include <iostream>
#include "opencv2/opencv.hpp"
#include "caffe/caffe.hpp"
#include "json/json.h"
Error that I get, like:
Undefined symbols for architecture x86_64:
"Json::StyledWriter::write(Json::Value const&)", referenced from:
image_list_processing(int, char**) in my_tool.cpp.o
So the question is how to add lib to linking process? Should I modify https://github.com/BVLC/caffe/blob/master/tools/CMakeLists.txt or maybe I should add separate file under tools/json/CMakeLists.txt?
This is not an error of missing .h file. You need to link your code to the shared object (libjsoncpp.so of similar) for your code to access (link) compiled json functions.
add -L /path/to/libjson_folder and -ljsoncpp flags to the linking stage of your makefile.
I have a sensor that in their SDK, they are calling QT5 package.
This is the GCC command to build the programgcc Main.c -o main -L../../Release -L/usr/lib/arm-linux-gnueabihf -lQt5SerialPort -lLeddarC -lLeddar -lLeddarTech -lstdc++
But after that I'm getting these errors:
../../Release/libLeddar.so: undefined reference to `QString::toLocal8Bit_helper(QChar const*, int)'
../../Release/libLeddarC.so: undefined reference to `QString::toUtf8_helper(QString const&)'
../../Release/libLeddarC.so: undefined reference to `__cxa_throw_bad_array_new_length#CXXABI_1.3.8'
I think Qstring is a part of QtCore, I tired to find it to add to gcc but I just find /usr/lib/arm-linux-gnueabihf/libQtCore.so.4 that is basically based on Qt4 and not 5.
I aleady found the location of Qt5SerialPort at /usr/lib/arm-linux-gnueabihf .But I don't know why I'm getting error for QString
Could you please help me with solving this issue?
When I look for QString I got this:
/usr/include/qt5/QtCore/QStringRef
/usr/include/qt5/QtCore/QStringData
/usr/include/qt5/QtCore/QStringBuilder
/usr/include/qt5/QtCore/QStringMatcher
/usr/include/qt5/QtCore/QStringList
/usr/include/qt5/QtCore/QStringListModel
/usr/include/qt5/QtCore/QStringDataPtr
/usr/include/qt5/QtCore/QString
/usr/include/qt5/QtCore/QStringListIterator
It seems that They are in include folder but I don't know how I can call them with GCC since they are not build *.so libraries.
Think you need add new -lQtCore option to gcc command.
Ok. So here goes. I am currently trying to add and use a dynamic library called OpenCV into a Xcode project of mine. I first installed MacPorts using the .pkg. Then I opened Terminal and ran "sudo port install opencv". MacPorts then installed all sorts of dependencies (FFMPEG/etc) and then installed OpenCV into the "/opt/local/lib" folder for the .dylib files and into "/opt/local/include" folder for the header files. Then I opened Xcode and opened command line utility application project. I added a group to my project and then added all the .dylib files inside of it (I think these are called references to the dynamic libraries, but I am not sure - I am a total beginner - I learned C++, my first programming language, merely a week ago"). After that, I clicked on my project file thing inside of Xcode and went to Build Settings and then changed the "Header Search Paths" under the "Search Paths" tab to the /include folder I mentioned previously. The Library Search Path was already set to the /lib folder since I added the .dylib files already (I think that's what happened - not sure). Anyways, then I copied and pasted the following sample code from the opencv website into my main.cpp file just to test whether or not my library works.
//******************************Sample Code ************************************************
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <iostream>
using namespace cv;
using namespace std;
int main( int argc, char** argv ) {
if( argc != 2) {
cout <<" Usage: display_image ImageToLoadAndDisplay" << endl;
return -1; }
Mat image;
image = imread(argv[1], CV_LOAD_IMAGE_GRAYSCALE);
if(! image.data ) {
// Read the file
// Check for invalid input
cout << "Could not open or find the image" << std::endl ;
return -1; }
namedWindow( "Display window", CV_WINDOW_NORMAL );// Create a window for display.
imshow( "Display window", image ); // Show our image inside it.
waitKey(0); // Wait for a keystroke in the window
return 0; }
//********************END OF SAMPLE FILE CODE **********************************************
After I did all that and before I hit run, I think it is important to note that Xcode did not complain that it couldn't find my header files, and also it didn't complain about any syntax errors with the new functions the library should've added. In short, there were no errors highlighted on the main.cpp file. All the errors, however, started showing up after I hit the Run button inside of Xcode. Here are all the errors that it generated:
**************Errors from Xcode after I hit Run*********************************************
Stupid Stack Overflow won't let me post images, so here is the link to the error photo:
*****************END OF BLOCK***************************************************************
So, yeah, I have no clue what I am doing at this point and am totally lost. Did I not follow the correct steps in adding a dynamic library to my project? Oh, and I forgot what it was, but I somehow got Xcode to ignore those semantic issues (I cannot remember how I did this or if that was what I did), but once the semantic issues are ignore, the only error that remains seems to be something related to a "Mach-O Linker Error" which says something on the lines of: "undefined symbols....architecture/etc" and then says that the undefined symbol was one of the library functions that I was calling in my main.cpp file. But that error no longer occurs since I deleted everything and started again. So now the only errors I get are the ones from the picture. So PLEASE HELP!!!! I am absolutely lost and I have been researching for weeks now, but I think the issue with me there is that I have no clue what I am looking for or what question I should be asking. The steps I listed above is only what I have done. Any insight will be much appreciated. THANKS IN ADVANCE!!!!!!
____________EDIT___________________
So I repeated the above steps again, but this time I get this error:
Ld /Users/Yash/Library/Developer/Xcode/DerivedData/OpenCVOptTEST-adchdkiefzmijfhahwtzcfqarzkw/Build/Products/Debug/OpenCVOptTEST normal x86_64
cd "/Users/Yash/Coding Folder/OpenCVOptTEST"
setenv MACOSX_DEPLOYMENT_TARGET 10.8
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ -arch x86_64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk -L/Users/Yash/Library/Developer/Xcode/DerivedData/OpenCVOptTEST-adchdkiefzmijfhahwtzcfqarzkw/Build/Products/Debug -L/opt/local/lib -F/Users/Yash/Library/Developer/Xcode/DerivedData/OpenCVOptTEST-adchdkiefzmijfhahwtzcfqarzkw/Build/Products/Debug -filelist /Users/Yash/Library/Developer/Xcode/DerivedData/OpenCVOptTEST-adchdkiefzmijfhahwtzcfqarzkw/Build/Intermediates/OpenCVOptTEST.build/Debug/OpenCVOptTEST.build/Objects-normal/x86_64/OpenCVOptTEST.LinkFileList -mmacosx-version-min=10.8 -stdlib=libc++ -lopencv_calib3d.2.4.6 -lopencv_contrib.2.4.6 -lopencv_core.2.4.6 -lopencv_features2d.2.4.6 -lopencv_flann.2.4.6 -lopencv_gpu.2.4.6 -lopencv_highgui.2.4.6 -lopencv_imgproc.2.4.6 -lopencv_legacy.2.4.6 -lopencv_ml.2.4.6 -lopencv_nonfree.2.4.6 -lopencv_objdetect.2.4.6 -lopencv_photo.2.4.6 -lopencv_stitching.2.4.6 -lopencv_superres.2.4.6 -lopencv_ts.2.4.6 -lopencv_video.2.4.6 -lopencv_videostab.2.4.6 -o /Users/Yash/Library/Developer/Xcode/DerivedData/OpenCVOptTEST-adchdkiefzmijfhahwtzcfqarzkw/Build/Products/Debug/OpenCVOptTEST
Undefined symbols for architecture x86_64:
"cv::namedWindow(std::__1::basic_string, std::__1::allocator > const&, int)", referenced from:
_main in main.o
"cv::imread(std::__1::basic_string, std::__1::allocator > const&, int)", referenced from:
_main in main.o
"cv::imshow(std::__1::basic_string, std::__1::allocator > const&, cv::_InputArray const&)", referenced from:
_main in main.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Check out Apple's documentation for working with Dynamic Libraries.
What these errors are telling you is that it can't find the object code (implementations) for these symbols during the Linking phase. From Apple's documentation, it looks like it expects to find the dylibs in /usr/local/lib not /opt/local/lib.
I want to use Google Protocol Buffers for C++ in XCode.
This is my directory where I have the library: /Developer/Protobuf.
What I did inside this directory, is compiled the .proto and produced the .pb.h & .pb.cc files. After this produced the object file:
clang++ -arch x86_64 -I./src -I./ -c file.pb.cc
Then:
ar -r file.pb.a file.pb.o
In XCode, in Build Phases -> Link Binary With Libraries I have added file.pb.a static library. In Build Settings -> Header Search Paths I have added /Developer/Protobuf/src. In Build Settings -> Librabry Search Paths I have added /Developer/Protobuf. In Build Settings -> User Header Search Paths I have added also /Developer/Protobuf/src.
But when I compiled the project I always get this kind of errors:
Undefined symbols for architecture x86_64:
"google::protobuf::DescriptorPool::generated_pool()", referenced from:
musicbrainz::protobuf_AssignDesc_musicbrainz_2eproto() in musicbrainz.pb.o
"google::protobuf::DescriptorPool::InternalAddGeneratedFile(void const*, int)", referenced from:
musicbrainz::protobuf_AddDesc_musicbrainz_2eproto() in musicbrainz.pb.o
"google::protobuf::MessageFactory::generated_factory()", referenced from:
musicbrainz::protobuf_AssignDesc_musicbrainz_2eproto() in musicbrainz.pb.o
"google::protobuf::MessageFactory::InternalRegisterGeneratedFile(char const*, void (*)(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&))", referenced from:
musicbrainz::protobuf_AddDesc_musicbrainz_2eproto() in musicbrainz.pb.o
.................................................................................
Maybe I am not creating the static library correct ?
First of all, you need to compile the Protocol Buffers static libraries using their makefiles, and then, link in the static libraries into your project. You should not be pulling in their source code into your Xcode project.
When linking the libraries into my project, I had the same 'undefined symbols' errors as you. Based on comment #19 in this discussion, running the following commands when building the Protocol Buffers libraries will make them go away.
$ ./configure CC=clang CXX="clang++ -std=c++11 -stdlib=libc++" CXXFLAGS="-O3" --disable-shared
$ make
I try to build a simple Qt 5 program on Mac. But I failed.
The code is very simple:
#include <QtWidgets/QApplication>
int main(int argc, char *argv[])
{
QApplication app (argc, argv);
return app.exec();
}
I used:
clang++ -I ~/Qt5.0.0/5.0.0/clang_64/include -L/Users/crazylion/Qt5.0.0/5.0.0/clang_64/lib test.cpp
Then I got this error:
Undefined symbols for architecture x86_64:
"QApplication::exec()", referenced from:
_main in test-jPGORy.o
"QApplication::QApplication(int&, char**, int)", referenced from:
_main in test-jPGORy.o
"QApplication::~QApplication()", referenced from:
_main in test-jPGORy.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Is there anything i missing?
Firstly, don't compile and link Qt projects by hand; use qmake and project files.
Run qmake -project in your source directory to generate a basic project file.
Edit the project file and add the following line: QT += widgets
Now run qmake to generate a makefile.
Now run make to build your program.
Secondly, you can simply #include <QApplication>
If you want to use clang++ in favor of qmake, you need to specify libraries to link against to, along with the library directory (which you supplied).
clang++ -I ~/Qt5.0.0/5.0.0/clang_64/include -L/Users/crazylion/Qt5.0.0/5.0.0/clang_64/lib -lQtCore -lQtGui test.cpp
I had the same problems and it seems to me that there is some sort of bug in the release it gave me some errors because out of a fresh install (using qt creator) i didn't have some obscure qt library (not the normal qt5 modules but some sort of library in development) so I tend to think that it could be qt's problem
That said I have some questions to better understand:
-are you using a IDE?
-if you are using one which is it?
-are you including all the modules in the *.pro for quake?
-have you used 4.8 version, did you experienced these problems with that?
P.S. if you do not have any particular necessity I suggest you to stick to version 4.8 for some time (as I am doing without problem) since 5.0 is just been released