How to link boost.build project to particular static library - c++

I use boost.build for my project. Of course, I use boost itself. Also, for test purposes I use google-test library with my project. I have to link my project with google-test's static library. I've found the workaround to do that for MinGW (for linux's gcc works too)
exe foo : $(IMPORTANT_PART) $(TEST_UTILITY_PART) : <toolset>gcc <linkflags>"../../libs/gtest-1.6.0/libs/gtest_main.a" <linkflags>-static <linkflags>-lpthread ;
It looks kind of ugly but it works. The rule for msvc looks much much more ugly
exe foo : $(IMPORTANT_PART) $(TEST_UTILITY_PART) : <toolset>msvc <linkflags>/LIBPATH:../../libs/gtest-1.6.0/libs <linkflags>/DEFAULTLIB:gtest_main-mdd.lib
<linkflags>/DEFAULTLIB:gtestd-md.lib
;
Is there more natural way to link target with external static library in boost.build project file.
P.S. Of cource using google-test and boost mix smells not good, but anyway there are a lot of external libraries that cover areas boost doesn't cover.
TIA

Great! Thank the persond who pointed me http://www.boost.org/boost-build2/doc/html/bbv2/tutorial/prebuilt.html page. (the comment disappeared) It seems to be, I did read this page not carefully. And target lib with file property does the thing I searched for. Thanks!
As for using google test and boost build I did this way: I made Jamfile for google-test. It is very simple:
gtest.lib/Jamfile
project gtest_main
: requirements <include>../../../libs/gtest-1.6.0/include
<include>../../../libs/gtest-1.6.0/
: source-location ../../../libs/gtest-1.6.0
: build-dir ../../../libs/gtest-1.6.0/bin.b2 ;
lib gtest_main : src/gtest_main.cc src/gtest-all.cc : <link>static ;
Then, somewhere in my project file:
use-project /gtest : ./gtest.lib ;
and mentioning //gtest in project's requirements section.

Related

Cannot use the C++ `std::filesystem` library with Meson build

I am trying to build a piece of C++ code that uses the new C++17 Filesystem library, using the Meson build system.
This is the piece of meson.build file involved:
if not compiler.has_header('filesystem') # This is OK
warning('The compiler has no <filesystem> header file')
endif
filesystem_dep = dependency('libc++fs', modules : ['filesystem'])
test_exe = executable('test', test_src,
include_directories : include_dirs,
dependencies : filesystem_dep
)
In case the boost::filesystem library is used, this should be the correct syntax:
filesystem_dep = dependency('boost', modules : ['filesystem'])
How can I specify I want the version contained in the Standard C++ library? This is what I tried without success: 'libc++fs', 'stdlib', 'stdc++', 'libc++', 'c++', 'c++17'.
This is the error message I get from Meson:
src/meson.build:33:0: ERROR: Native dependency 'libc++fs' not found
The compiler I am currently using is LLVM/clang.
dependency() is for external libraries. Standard libraries should be configured using compiler command line with special functions like add_XXX_arguments(). So, try
add_project_arguments(['-stdlib=libc++'], language : 'cpp')
add_project_link_arguments(['-stdlib=libc++','-lstdc++fs'], language : 'cpp')
However, '-lstdc++fs' maybe not needed in your case.

Eclipse paho mqtt C++ as dependency in another project

I have not much clue how c and c++ works at compile and runtime!
We are trying to use Eclipse Paho C++ library as a dependency in the project and messed up right now.
We have reffered to https://github.com/eclipse/paho.mqtt.cpp/tree/master/src/samples and used the same code in our project but we get this error.
error: 'mqtt' has not been declared class callback : public virtual mqtt::callback
We also have the following in place
Copied all the C and C++ libs(libmqttpp.so libpaho-mqtt3a.so.1.0 libpaho-mqtt3c.so.1 libmqttpp.so.0 libpaho-mqtt3as.so libpaho-mqtt3c.so.1.0 libmqttpp.so.0.1 libpaho-mqtt3as.so.1 libpaho-mqtt3cs.solibpaho-mqtt3a.so libpaho-mqtt3as.so.1.0 libpaho-mqtt3cs.so.1
libpaho-mqtt3a.so.1 libpaho-mqtt3c.so libpaho-mqtt3cs.so.1.0) to /usr/local/lib
Copied .h files(MQTTAsync.h MQTTClient.h MQTTClientPersistence.h) to /usr/local/include
Apart from above 2 steps, do I need to add anything to my project to resolve the problem or I am missing anything.
Finally, It worked after doing the following steps
Download 'C' zip from http://build.eclipse.org/technology/paho/
Copy lib files to /usr/lib/
Modified SConscript(alljoyn/gateway/gwagent/GatewatConnector/samples/) to extend LIBS - gwcnc_env.Prepend(LIBS = ['paho-mqtt3a', 'paho-mqtt3c', 'alljoyn_about', 'alljoyn_services_common', 'alljoyn_notification', 'alljoyn_config', 'alljoyn_gwconnector'])

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

gnat gprbuild : how to build a dynamic dll and link with a static c++ library

I have a full Ada project I want to build to get a dynamic dll.
Therefore I have to link it with another static library (myanotherlibrary.lib).
I use this command line :
gprbuild -d "D:\My_grp_project\My_grp_project.gpr"
Here the content of the .gpr :
project My_grp_project is
Architecture := "x86";
for Languages use ("Ada");
for Source_Dirs use (".", "source", "source\common");
for Library_Dir use "dll\" & Architecture;
for Library_Ali_Dir use "ali\" & Architecture;
for Library_Name use "My_grp_project";
for Library_Kind use "dynamic";
for Object_Dir use "obj\" & Architecture;
package Linker is
for Default_Switches ("Ada") use ("-L.", "-lbar");
end Linker;
end My_grp_project;
I put "myanotherlibrary.lib" in the directory "D:\My_grp_project\", but it still doesn't link: "undefined reference to ..."
Could anyone help me please ?
Regards
Glen
Looking at the docs, I think you should be using the Library_Options attribute instead of package Linker:
for Library_Options use ("-L.", "-lbar”);
(I’m confused - do you mean myanotherlibrary.lib or bar.lib?)
I’d be a bit concerned about using a static library from a dynamic library: I’d expect the dynamic library to be built with -fPIC or equivalent switch to get position-independent code, so that the same loaded library binary can be seen at different addresses in each of the executables using it.
Here the solution I finally found.
It is not possible to link static library compiled with MSVC. I had to compile my static library with GCC (same version as the one included in GNAT).
I had to add "Library_Options" options, without "-L" and "-l" arguments (another problem I passed). Note that package Linker is not taken into account while building a dynamic library. Note also that paths shall have no spaces !
project My_grp_project is
for Languages use ("Ada");
for Source_Dirs use (".", "source", "source\common");
for Library_Dir use “dll";
for Library_Ali_Dir use "ali";
for Object_Dir use "obj";
for Library_Name use "My_grp_project";
for Library_Kind use "dynamic";
for Library_Options use ("path\myanotherlibrary.a", "path_to_GNAT\libstdc++.a");
end My_grp_project;
I builded the project in the GPS (default option) : "Build All"
In result I do have my dynamic library "libMy_grp_project.dll"
Voilà.
Thanks !

no override found for 'vtkPolyDataMapper'

I'm trying to use vtk in my code, but I'm having problems running an example. I have almost no clue about the reasons since it's the first time I'm using it and I'm not very experienced.
I'm using visual studio 2012 and x64 platform.
Since I don't really know which libs should I use I added all of them to the "Additional Dependencies".
The example is given in this link.
The problem is that when I run it, the window shows this message
Generic Warning: In C:\location\VTK6.0.0\Rendering\Core\vtkPolyDataMapper.cxx, line 27
Error: no override found for 'vtkPolyDataMapper'.
which corresponds to this line
// Return NULL if no override is supplied.
vtkAbstractObjectFactoryNewMacro(vtkPolyDataMapper)
And the error that visual studio shows is
First-chance exception at 0x000007F7AA106C8F in Test.exe: 0xC0000005: Access violation reading location 0x0000000000000000.
Does anyone know how to solve this problem or at least what does this error mean?
I too was getting this error. The error means that the linker can't find the definition for the vtkPolyDataMapper method. One has to note which vtk rendering backend they used, during build. It will probably be either vtkRenderingOpenGL, or vtkRenderingOpenGL2. Go to your build/lib folder and search for either one of these. I have VS 2015 Community and had the vtkRenderingOpenGL2, with vtk-7.1 built on Windows 8.1, x86_64 Platform, Release configuration.
I fixed the issue by inserting the 3 following lines at the very top of my source files, before any other preprocessor directives:
#include "vtkAutoInit.h"
VTK_MODULE_INIT(vtkRenderingOpenGL2); // VTK was built with vtkRenderingOpenGL2
VTK_MODULE_INIT(vtkInteractionStyle);
This initializes the specified VTK modules. CMake includes these by default, but other compilers such as VS do not.
The last two lines can be combined into the following:
#define vtkRenderingCore_AUTOINIT 2(vtkRenderingOpenGL2, vtkInteractionStyle)
According to the VTK migration guide, if you are not using CMake to compile your code, you need to add some #defines. For VTK 6.0, these lines need to go before any other VTK #includes:
#define vtkRenderingCore_AUTOINIT 4(vtkInteractionStyle,vtkRenderingFreeType,vtkRenderingFreeTypeOpenGL,vtkRenderingOpenGL)
#define vtkRenderingVolume_AUTOINIT 1(vtkRenderingVolumeOpenGL)
You are missing include(${VTK_USE_FILE}) in your CMakeLists.txt file.
Assuming your are using OpenGL2, you should initialise the vtkRenderingOpenGL2 module, ensuring its object factory is correctly registered:
VTK_MODULE_INIT(vtkRenderingOpenGL2)
You should call this macro in the global scope (ex. main.cpp) as documented in the source code:
Initialize the named module, ensuring its object factory
is correctly registered and unregistered. This call must be made in
global scope in the translation unit of your executable (which can
include a shared library, but will not work as expected in a static
library).
#include "vtkAutoInit.h"
VTK_MODULE_INIT(vtkRenderingOpenGL);
The above snippet if included in the global scope will ensure the
object factories for vtkRenderingOpenGL are correctly registered and
unregistered.
How do you know which module to include?
The easiest method is to search in the VTK build folder for "vtkClassThatNeedsAnOverride", i.e. "vtkPolyDataMapper" in your case (note the use of quotes ".) and looking for a *ObjectFactory in your search results:
Rendering/OpenGL2/vtkRenderingOpenGL2ObjectFactory.cxx:
this->RegisterOverride("vtkPolyDataMapper",
"vtkOpenGLPolyDataMapper",
"Override for vtkRenderingOpenGL2 module", 1,
vtkObjectFactoryCreatevtkOpenGLPolyDataMapper);
It may be even more beneficial to look for RegisterOverride("vtkPolyDataMapper".
Which object factories exist?
To obtain a list of all existing modules that you could initialise, you can search for _AutoInit_Construct. *_AutoInit_Construct is the method that is called by VTK_MODULE_INIT.
As an alternative, you can look at all classes that derive from vtkObjectFactory.
A second alternative is to look for all calls to RegisterOverride.
Further information
VTK 6 Migration: Factories now require defines
Build System Migration: You do not need to call VTK_MODULE_INIT manually using cmake by calling include(${VTK_USE_FILE}) in your CMakeLists.txt
Note that I originally wrote this answer for a duplicate question, but I think the general information about solving this problem may be of interest for other people with the same error message.
I would recommend following the guide here, with the VTK_MODULE_INIT macro being the most reliable, with the guide here providing a high level overview of the changes needed. You must link to vtkRenderingOpenGL for example to get most of the standard overrides. If you use CMake then specifying it on the COMPONENTS argument to find_package would cause it to be added to VTK_LIBRARIES, and including VTK_USE_FILE would cause the correct compiler definitions to be added.
I had the same issue at my platform;
Visual Studio 2015
Windows 7
VTK 6.3
I followed VTK/Build System Migration from Marcus D. Hanwell's post, and it works. My additonal lines are;
#include <vtkAutoInit.h>
VTK_MODULE_INIT(vtkRenderingOpenGL);
VTK_MODULE_INIT(vtkInteractionStyle);
on the top of preprocessor. The difference from RestlessC0bra's post is probably OpenGL version.
When using ParaView's Catalyst libraries you have to add the following in addition to include("${PARAVIEW_USE_FILE}"):
set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS ${VTK_DEFINITIONS})
A quick hack solution: In CMakeList.txt file, replace vtkRendering${VTK_RENDERING_BACKEND} with vtkRenderingOpenGL2. The reason why we need this is because Cmake does not know where the rendering core is. By specifying it, we can use the rendering core to override the proper method.
The proper solution should be replace the whole find_package paragraph with:
find_package(VTK REQUIRED COMPONENTS vtkCommonCore)
find_package(VTK COMPONENTS
vtkFiltersSources
vtkInteractionStyle
vtkRendering${VTK_RENDERING_BACKEND})
The first find_package lets the CMake know where to find the packages, then second find_package would know where to find vtkRendering${VTK_RENDERING_BACKEND}.