How to build additional caffe tools? - makefile

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.

Related

MSVC fatal error LNK1120: 1 unresolved externals with FFMPEG libs

I am trying to utilize the ffmpeg libraries in a program of my own and am having trouble linking them. Specifically, In my a basic program I am receiving fatal error LNK1120: 1 unresolved externals errors. The program is:
#include <iostream>
#include <libswresample/swresample.h>
int main()
{
std::cout << "Hello World!\n";
struct SwrContext* swr_ctx = swr_alloc();
if (!swr_ctx) {
std::cout << "Could not allocate resampler context";
}
}
I downloaded prebuild libraries from https://ffmpeg.zeranoe.com/builds/, specifically the Windows x64 dev package which includes the .def/.lib as well as .dll files.
I originally tried (and intend to ultimately use) cmake to generate the MSVC sln files. The cmake file is:
cmake_minimum_required(VERSION 3.5)
project(ffmpeg_jni)
# Find the JNI bits
find_package(JNI)
# Search for the ffmpeg libraries
set(ffmpeg_include_hint "ffmpeg-dev/include")
set(ffmpeg_lib_hint "ffmpeg-dev/lib")
find_path(SWRESAMPLE_INCLUDE_DIR libswresample/swresample.h PATHS ${ffmpeg_include_hint})
find_library(SWRESAMPLE_LIBRARY swresample PATHS ${ffmpeg_lib_hint})
add_library(swresample SHARED IMPORTED)
set_target_properties(swresample PROPERTIES
IMPORTED_LOCATION "${SWRESAMPLE_LIBRARY}"
IMPORTED_IMPLIB "${SWRESAMPLE_LIBRARY}"
INTERFACE_INCLUDE_DIRECTORIES "${SWRESAMPLE_INCLUDE_DIR}"
)
# Setup basic include dirs
set(includeDIRS
src/main/cpp
${JAVA_INCLUDE_PATH})
# Setup windows specific includes
set(includeDIRS
${includeDIRS}
${JAVA_INCLUDE_PATH}/Win32)
include_directories(${includeDIRS})
set(WRAPPER_SRC
src/main/cpp/logging.c
src/main/cpp/logging.h
src/main/cpp/main.cpp)
add_library(ffmpeg_jni SHARED ${WRAPPER_SRC})
target_link_libraries(ffmpeg_jni PRIVATE swresample)
The generated solution compiles and has proper access to the include files (Visual Studio can even take me to the declarations). The issue comes in the linking phase of the build where I receive:
error LNK2019: unresolved external symbol "struct SwrContext * __cdecl
swr_alloc(void)" (?swr_alloc##YAPEAUSwrContext##XZ) referenced in
function main
Thinking that I perhaps had something wrong in cmake since I am still pretty new with it I tried making a simple demo as a pure visual studio project following what I have found in countless online demos for adding an external library to a project. Specifically this included:
Adding the directory containing the header files to Properties->C/C++->General->Additional Include Directories
Adding the directory containing the .lib files to Properties->Linker->General->Additional Library Directories (Note that the cmake path did not do this but instead added the lib file via a relative path)
Adding the .lib file to Properties->Linker->Input->Additional Dependencies
At this point any searching efforts I undertake show me different people doing the same things which tells me I've been looking at this too long to find the answer myself and its something trivial that I'm missing/not understanding.
If you are compiling your project as c++, then include FFmpeg headers as below which tells your c++ compiler to handle FFmpeg headers as C instead of C++.
extern "C" {
#include <libswresample/swresample.h>
}

LINK error in visual studio with boost date_time library

I built date_time library only and set up property page like this:
linker > input > additional dependencies:
libboost_date_time-vc120-mt-gd-1_55.lib boost_date_time-vc120-mt-gd-1_55.lib;%(AdditionalDependencies)
VC++ directories > library directories:
C:\boost_1_55_0\stage\lib;$(LibraryPath)
VC++ directories > include directories:
C:\boost_1_55_0;$(IncludePath)
when runing build I got following error:
1>LINK : fatal error LNK1104: cannot open file
'boost_date_time-vc120-mt-gd-1_55.lib.obj'
linker can't find the *.obj file, I can't find it either, where do need to look for *.obj file and what to do once I find it?
You shouldn't specify additional dependencies. Boost will auto link libraries using #pragma comment(lib, "<lib name>") when you include their headers. Try removing those explicit dependencies and rebuild.

How to build qt 5 project on mac

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

Trying to get stasm to work on Ubuntu

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.

Including headers in an Xcode 4.2.1 project

I'm trying to use a library, specifically SOIL (Simple OpenGL Image Library) in Xcode 4.2.1. Under Build Phases -> Link Library with Libraries I add all the .h and .c files that came with the SOIL zip archive.
When I build the project, I get the following error message for every .h and .c file added:
warning: skipping file '/Users/saw/XcodeProjects/Assignment01 copy/Assignment01/image_DXT.c'
(unexpected file type 'sourcecode.c.c' in Frameworks & Libraries build phase)
and a linker error:
"_SOIL_load_OGL_texture", referenced from: Init() in main.o Symbol(s)
not found for architecture x86_64 Clang: error: linker command failed
with exit code 1 (use -v to see invocation)
.h and .c files aren't libraries. Add the .c files to the compile phase and just #import the .h files where needed.
To verify linking I have done the following:
Create a new Mac Cocoa application.
Add 10 files from the SOIL src
folder: SOIL.c, image_DXT.h, stbi_DDS_aug.h, SOIL.h, image_helper.c,
stb_image_aug.c, stbi_DDS_aug_c.h, image_DXT.c, image_helper.h, and
stb_image_aug.h.
Tell Xcode to copy them to my project.
Add one line
to my app delegate's applicationDidFinishLaunching: method:
SOIL_load_OGL_texture( "img_test.png", SOIL_LOAD_AUTO,
SOIL_CREATE_NEW_ID, 0 );.
Build the target for running.
Although there are a variety of compiler warnings about data conversion, these steps produce an executable with no linker errors.
Try adding -framework to your framework's name in the "Other Linker Flags" such as:
-framework SOIL

Resources