Library search paths with Boost.Build - boost-build

I am trying to use Boost.Build as a C++ build system. This will included projects with have nothing to do with boost. My question is how do I get Boost.Build to add an entry to the linker's library search path. Here's my JAMFILE:
project RegExTest
: requirements <include>"C:/Libraries/boost_1_57_0" <search>"C:/Libraries/boost_1_57_0/stage32/lib"
: default-build debug
;
cpp-pch pch : precomp.hpp ;
exe RegExTest : [ glob *.cpp ] pch ;
Note that this example is using a Boost library but this in general is not the case. I don't want to use the library rule if I don't have to! I didn't need to to get my include path added so why should I have to to add a search path to the linker?

You want to use the "library-path" feature to add library search paths (-L) for the linker:
project RegExTest
: requirements
<include>"C:/Libraries/boost_1_57_0"
<library-path>"C:/Libraries/boost_1_57_0/stage32/lib"
: default-build debug
;
cpp-pch pch : precomp.hpp ;
exe RegExTest : [ glob *.cpp ] pch ;
Unfortunately it looks like it's an undocumented feature for which you would have had to read the source code to find

Related

Native C++ Code in Android Studio with a Static Library

I am trying to make a native C++ code in Android Studio and with CMake. My C++ code uses precompiled static library (.a file).
I included its header .h in my C++ code. I also linked the location of the .h and the .a files in my CMakeList.txt as below:
include_directories(".h file location")
Then:
add_library(lib_fastcv STATIC IMPORTED)
set_target_properties(lib_fastcv PROPERTIES IMPORTED_LOCATION
".a file location")
And at the end:
target_link_libraries (...lib_fastcv....)
However, as soon as I use any function from the .a static library it complains that it cannot recognize the function which means the static library is not linked correctly to my C++ code.
Does anyone know what else I need to do?
Should I also edit my build.gradle to include information about the library file?
this is my solution:
So, first of all, CMake can be weird to use at the beginning.
1- native-lib1 is the output product of CMake. Later java will only see .so of this
add_library( # This is out .so product (libnative-lib1.so)
native-lib1
# Sets the library as a shared library.
SHARED
# These are the input .cpp source files
native-lib.cpp
SRC2.cpp
Any other cpp/c source file you want to compile
)
2- Any library that you included in your souse file, its .h needs to be addressed here:
target_include_directories(# This is out .so product (libnative-lib1.so)
native-lib1 PRIVATE
${CMAKE_SOURCE_DIR}/include)
3- Any actual library you used, its atual .a or .cpp should be addrressed to CMake this way:
target_link_libraries(
# This is out .so product (libnative-lib1.so)
native-lib1
#These are any extra library files that I need for building my source .cpp files to final .so product
${CMAKE_SOURCE_DIR}/lib/libfastcv.a
# Links the target library to the log library
# included in the NDK.
${log-lib})
Then build.gradle it should be mentioned what abi formats we want it to make to make sure you pre built .a files are compatible.
flavorDimensions "version"
productFlavors {
create("arm7") {
ndk.abiFilters("armeabi-v7a")
}
Finally, as a note, the below command did not work to filter abis and above command work, even though they look similar in logic and form to me:
cmake {
cppFlags "-std=c++11"
abiFilters 'armeabi-v7a'
}
}
ndk {
// Specifies the ABI configurations of your native
// libraries Gradle should build and package with your APK.
// This is not working to eliminate
abiFilters 'armeabi-v7a'
}
}

How do I pass cxxflags to Boost libraries from within my jamfile?

I have a project with some requirements, one of which is to set the c++11 compiler/linker flags:
jamroot.jam:
project
: requirements
<toolset>clang:<cxxflags>"-stdlib=libc++ -std=c++11"
<toolset>clang:<linkflags>"-lc++"
# ... etc
;
lib mylibrary
: #sources
[ glob source/*.cpp ]
/boost/filesystem
/boost/system
/boost/thread//boost_thread
;
The library-specific sources are being compiled with the necessary c++11 flags, however the Boost libraries mentioned do not. This is causing no end of binary incompatibilities and linker errors.
I do not want to specify the cxxflags explicitly in either the user-config or the command line. I would like to make sure the jamroot/jamfiles are all that is necessary to build the project properly.
How do I "pass in" the desired cxxflags to the dependent Boost libraries?
Update: I recently tried using an alias to accomplish my goal. From the docs:
Another use of the alias rule is to change build properties. For example, if you want to use link statically to the Boost Threads library, you can write the following:
alias threads : /boost/thread//boost_thread : <link>static ;
However setting this up for boost_filesystem and rebuilding, say, path.cpp still omits the properties I am trying to build with.
This was resolved by setting up a feature (thanks to Steven Watanabe):
feature.feature cpp11 :
on :
composite optional propagated
;
feature.compose <cpp11>on :
<cxxflags>"-stdlib=libc++ -std=c++11"
<define>BOOST_NO_CXX11_NUMERIC_LIMITS=1
<linkflags>"-lc++"
;
project
: requirements
<cpp11>on
# ... etc
;
Apparently this is the only way to get variables to propagate to dependent libraries.

Use of external C++ headers in Objective-C

In my iOS project I need to use an external library written in C++. The C++ header files are all in one directory.
I've added these C++ headers to my Xcode project, and also specified a header search path (in Build Settings).
The issue is that these C++ headers include each other using < > angle brackets. This results in:
'filename.h' file not found with <angled> include, use "quotes" instead.
The weird thing is that Xcode does not complain about all headers. Also the same header #include'd in one file is fine, while an issue when #include'd in another. I think this is caused by the fact that these headers #include each other.
Why doesn't the search path work?
Is there a way to resolve this without modifying these header files?
Thanks!
#include <bla.h>
is meant for standard library or framework headers, and the search strategy
Is different than that used for
#include "bla.h"
See for example
What is the difference between #include <filename> and #include "filename"?
As a workaround, you can set the Xcode build setting "Always Search User Paths" to YES.
Starting from a "blank" application project:
Create a folder "Libraries" in your application's project - preferable as a sibling to your MyApp.xcodeproj file, but it can be anywhere. Create subfolders for each Configuration (Debug, Release, etc.) and possibly for each architecture (armv7, armv7s, arm64) unless the binary is universal binary archive containing all architectures.
Get the headers of the third party library and the static library binaries (possibly more than one for different platforms, Configurations and architectures) and move them into the "Library" folder into corresponding subfolders (which you may need to create):
For example, assuming you had a universal binary (armv7, armv7s, arm64) and Debug and Release versions of that library:
Now, the folder structure is assumed to be as follows:
$(SRCROOT)/Libraries
Debug-iphoneos
include
ThirdParty
third_party.hh
...
libThirdParty.a
Release-iphoneos
include
ThirdParty
third_party.hh
...
libThirdParty.a
MyApp.xcodeproj
"Library Search Paths" Build Setting:
Drag the "Libraries" folder into your Xcode project. This may automatically create a library search path in the build settings. Please verify this, and if it is not correct, fix it.
Given the example, add the following library search paths for Debug and Release Configuration:
Debug: Library Search Paths: $(SRCROOT)/Libraries/Debug-iphoneos
Release: Library Search Paths: $(SRCROOT)/Libraries/Release-iphoneos
You may have different library search paths for particular Configuration and Target platform pairs. Set different path's in the build setting accordingly.
"Header Search Paths" Build Setting:
Given the example, add the following header search path to the Debug and the Release Configuration:
Debug: Header Search Paths: $(SRCROOT)/Libraries/Debug-iphoneos/include
Release: Header Search Paths: $(SRCROOT)/Libraries/Release-iphoneos/include
Likewise, you may have different paths for particular Config/Target pairs - although the headers may be the same.
Link your app against the C++ standard library by adding -lc++ to the Other Linker Flags build setting.
Import the header in your files as follows:
#import <ThirdParty/third_party.hh>
In Xcode 9, I need to add header files path to the Header Search Paths build setting, not User Header Search Paths.
Xcode will append User Header Search Paths to compile command as -iquote options, but append Header Search Paths as -I options. That's the key difference.
In XCode after setting the "User Header Search Paths" to point to your library's directory, you also have to make sure that a field called "Always Search User Paths" is set to "Yes"
This solved the problem I was having: with <boost/signals2.hpp> file not found with <angled> include, use "quotes" instead.
my two cents for OSX / Mysql.
(by the way I ask why that bogus use of <> in mysql... anyway..)
As per Xcode 11 warning, "Disabling it is strongly recommended.",
I prefer to patch another setting, leaving "Always Search User Paths" to "No".
I set:
HEADER_SEARCH_PATHS = "/usr/local/mysql/include".
LINKER:
I)
If You got link error, add "libmysqlclient.a" usually in "/usr/local/mysql/lib", simply dragging from Finder)
II: You can get a worst error...
"/usr/local/lib/libmysqlclient.21.dylib: code signature in (/usr/local/lib/libmysqlclient.21.dylib) not valid for use in process using Library Validation: mapping process and mapped file (non-platform) have different Team IDs"
As that lib is not signed. Simply in Entitlemens:
(in XML):
..
<dict>
<key>com.apple.security.cs.disable-library-validation</key>
<true/>
</dict>
...

Is there a simple way to include library files in MSVC?

In building a my application, I have a fairly long list of *.Lib files required for compilation. Here is my compilation instruction:
Bin\cl.exe Main.cpp /EHsc /I atlmfc\include /I Includes /I Includes\Winsdk atlmfc\lib\amd64\nafxcw.Lib Libs\libcmt.lib Libs\Kernel32.Lib Libs\User32.Lib Libs\Gdi32.Lib Libs\MSImg32.Lib Libs\ComDlg32.Lib Libs\WinSpool.Lib Libs\AdvAPI32.Lib Libs\Shell32.Lib Libs\ComCtl32.Lib Libs\ShLwApi.Lib Libs\Uuid.lib atlmfc\lib\amd64\atls.lib Libs\Ole32.Lib Libs\OleAut32.Lib Libs\oldnames.lib Libs\WS2_32.Lib Libs\MsWSock.Lib Libs\OleAcc.Lib Libs\comsuppw.lib Libs\GdiPlus.lib Libs\Imm32.Lib Libs\WinMM.Lib Libs\MsXml2.Lib Libs\OleDlg.Lib Libs\Urlmon.Lib /link/SUBSYSTEM:WINDOWS
All of these files are in the same directory. Well, one or two directories anyway. Is there some way that I can just tell the compiler to look in those directories for files that it needs, instead of typing out every single one?
Are you looking for http://www.lavishsoft.com/wiki/index.php/Visual_Studio_Paths or http://msdn.microsoft.com/en-us/library/1xhzskbe(v=vs.80).aspx? As already explained by Roman R. you can use the pragma command afterwards in your files. This way you can always see which libs are required without looking at the project configuration. If you don't want to use the pragma command there should be a linker section in your project configuration where you can add the libs.

Using Boost.build to include a library

I am using boost.build to compile a c++ code which references a library, CGNS, but am having some difficulty with using boost.build to do so. CGNS compiles to a library, with a folder for the platform, for example [path]/LINUX for the linux build. I would like to include the library [path]/LINUX/libcgns.a in the build. I would like this to be cross-platform, so that the LINUX directory is referenced for LINUX builds and the WIN directory is used for WIN builds (I believe there are platform conditionals for this).
I managed to include the library header files, but how do I go about the conditional include of the library? My simple test Jamroot.jam, where main.cpp is just an example from the CGNS docs.
exe CGNSTest
: src/main.cpp
: <include>../Dependencies/cgnslib ;
Also, I would like to build in the CGNS library into my binary (static reference?)
Using two references, http://www.highscore.de/cpp/boostbuild/, and http://www.boost.org/doc/tools/build/doc/userman.pdf, I created something that works, but it may not be the ideal.
lib cgns
: # sources
: # requirements
<name>cgns
<target-os>linux:<search>../Dependencies/cgnslib/LINUX
<target-os>windows:<search>../Dependencies/cgnslib/WIN32
: # default-build
: # usage-requirements
<include>./../Dependencies/cgnslib ;
alias static_libraries : cgns : <link>static ;
exe CGNSTest
: src/main.cpp static_libraries
: <target-os>windows:<linkflags>/NODEFAULTLIB:MSVCRTD ;