How to use Bazel as a build tool in Conan.io - c++

I am trying to use Conan for package management and Bazel as build tool for my C++ Codes. The reason I am using conan is because JFrog Artifactory supports it, which I am using as my Artifactory Repository.
To do that I came up with the following plan :
$/home/mytimer=> ls -lrt
0 Sep 25 11:57 WORKSPACE
4096 Sep 25 12:00 build/
4096 Sep 25 12:02 main/
$/home/mytimer=> ls -l main
total 4
60 Sep 25 12:02 BUILD
61 Sep 25 11:56 conanfile.txt
955 Sep 25 11:56 timer.cpp
$/home/mytimer=> ls -l build
total 8
1266 Sep 25 12:00 conanbuildinfo.gcc
1875 Sep 25 12:00 conaninfo.txt
( This is after I executed conan --install ../main )
$/home/mytimer=> cat cat main/conanfile.txt
[requires]
Poco/1.7.8p3#pocoproject/stable
[generators]
gcc
$/home/mytimer=>cat build/conanbuildinfo.gcc
-DPOCO_STATIC=ON -DPOCO_NO_AUTOMATIC_LIBS -I"/home/.conan/data/Poco/1.7.8p3/pocoproject/stable/package/da23483d46b7229cbae8615ce1ea2594635f3a5f/include" -I"/home/.conan/data/OpenSSL/1.0.2l/conan/stable/package/c8dc3f0797f6d24f3c80634ae2854ddf9ee34334/include" -I"/home/.conan/data/zlib/1.2.11/conan/stable/package/82b1dd29b2e9143665c77ef477100c690d719cbf/include" -Wl,-rpath="/home/.conan/data/Poco/1.7.8p3/pocoproject/stable/package/da23483d46b7229cbae8615ce1ea2594635f3a5f/lib" -Wl,-rpath="/home/.conan/data/OpenSSL/1.0.2l/conan/stable/package/c8dc3f0797f6d24f3c80634ae2854ddf9ee34334/lib" -Wl,-rpath="/home/.conan/data/zlib/1.2.11/conan/stable/package/82b1dd29b2e9143665c77ef477100c690d719cbf/lib" -L"/home/.conan/data/Poco/1.7.8p3/pocoproject/stable/package/da23483d46b7229cbae8615ce1ea2594635f3a5f/lib" -L"/home/.conan/data/OpenSSL/1.0.2l/conan/stable/package/c8dc3f0797f6d24f3c80634ae2854ddf9ee34334/lib" -L"/home/.conan/data/zlib/1.2.11/conan/stable/package/82b1dd29b2e9143665c77ef477100c690d719cbf/lib" -lPocoUtil -lPocoMongoDB -lPocoNet -lPocoNetSSL -lPocoCrypto -lPocoData -lPocoDataSQLite -lPocoZip -lPocoXML -lPocoJSON -lPocoFoundation -lpthread -lrt -lssl -lcrypto -ldl -lz -D_GLIBCXX_USE_CXX11_ABI=0 -m64 -s -DNDEBUGdevc
$/home/mytimer=> cat build/conaninfo.txt
[settings]
arch=x86_64
build_type=Release
compiler=gcc
compiler.libcxx=libstdc++
compiler.version=6.3
os=Linux
[requires]
Poco/1.Y.Z
[options]
[full_settings]
arch=x86_64
build_type=Release
compiler=gcc
compiler.libcxx=libstdc++
compiler.version=6.3
os=Linux
[full_requires]
OpenSSL/1.0.2l#conan/stable:c8dc3f0797f6d24f3c80634ae2854ddf9ee34334
Poco/1.7.8p3#pocoproject/stable:da23483d46b7229cbae8615ce1ea2594635f3a5f
zlib/1.2.11#conan/stable:82b1dd29b2e9143665c77ef477100c690d719cbf
[full_options]
OpenSSL:386=False
OpenSSL:no_asm=False
OpenSSL:no_bf=False
OpenSSL:no_cast=False
OpenSSL:no_des=False
OpenSSL:no_dh=False
OpenSSL:no_dsa=False
OpenSSL:no_hmac=False
OpenSSL:no_md2=False
OpenSSL:no_md5=False
OpenSSL:no_mdc2=False
OpenSSL:no_rc2=False
OpenSSL:no_rc4=False
OpenSSL:no_rc5=False
OpenSSL:no_rsa=False
OpenSSL:no_sha=False
OpenSSL:no_sse2=False
OpenSSL:no_threads=False
OpenSSL:no_zlib=False
OpenSSL:shared=False
Poco:cxx_14=False
Poco:enable_apacheconnector=False
Poco:enable_cppparser=False
Poco:enable_crypto=True
Poco:enable_data=True
Poco:enable_data_mysql=False
Poco:enable_data_odbc=False
Poco:enable_data_sqlite=True
Poco:enable_json=True
Poco:enable_mongodb=True
Poco:enable_net=True
Poco:enable_netssl=True
Poco:enable_netssl_win=True
Poco:enable_pagecompiler=False
Poco:enable_pagecompiler_file2page=False
Poco:enable_pdf=False
Poco:enable_pocodoc=False
Poco:enable_sevenzip=False
Poco:enable_tests=False
Poco:enable_util=True
Poco:enable_xml=True
Poco:enable_zip=True
Poco:force_openssl=True
Poco:poco_unbundled=False
Poco:shared=False
zlib:shared=False
[scope]
dev=True
[recipe_hash]
[env]
$/home/mytimer=> cat main/BUILD
cc_binary(
name = "timer",
srcs = ["timer.cpp"],
)
Now, I want to build the mytimer project using bazel as something like this :
$/home/mytimer=> bazel build --(some options) //main:timer
What should this some options be , so that bazel can read conanbuildinfo.gcc and use it to create the executable file ?

I used the genrule() feature of bazel to solve my problem in this way :
$/home/mytimer=> cat main/BUILD
genrule(
name = "timer",
outs = ["timer.out"],
cmd = "g++ /home/mytimer/main/timer.cpp#/home/mytimer/build/conanbuildinfo.gcc -o $# ",
)
/home/mytime=> bazel build -s //main:timer
WARNING: ignoring http_proxy in environment.
WARNING: Output base '/home/.cache/bazel/_bazel_user/274fa1325d85b25c2722794ea' is on NFS. This may lead to surprising failures and undetermined behavior.
INFO: Found 1 target...
>>>>> # //main:timer [action 'Executing genrule //main:timer']
(cd /home/.cache/bazel/_bazel_user/274fa1325d85b25c2722614/execroot/__main__ && \
exec env - \
LD_LIBRARY_PATH=<library paths>
PATH=<all other paths>
/bin/bash -c 'source external/bazel_tools/tools/genrule/genrule-setup.sh; g++ /home/bazel/examples/cpp-tutorial/mytimer/main/timer.cpp #/home/bazel/examples/cpp-tutorial/mytimer/build/conanbuildinfo.gcc -o bazel-out/local-fastbuild/genfiles/main/timer.out ')
Target //main:timer up-to-date:
bazel-genfiles/main/timer.out
INFO: Elapsed time: 1.050s, Critical Path: 0.50s
/home/mytime=> ls -lrt bazel-out/local-fastbuild/genfiles/main/
total 212
212000 Sep 26 14:42 timer.out
/home/mytime=> ./bazel-out/local-fastbuild/genfiles/main/timer.out
Callback called after 249 milliseconds.
Callback called after 749 milliseconds.
Callback called after 1249 milliseconds.
Callback called after 1749 milliseconds.
Callback called after 2249 milliseconds.
Callback called after 2749 milliseconds.
^C
So, by using genrule() feature, we can execute any shell command in bazel. Although this is not a so-called "bazel" way to generate artifacts (genrule() to bazel is same as "goto" command to C/C++ ), in this scenario, I do not see any other option to solve this issue.

You could also create a custom rule: https://docs.bazel.build/versions/master/skylark/rules.html for this. Ideally you would use a Skylark api to the C++ rules, to prevent reimplementing everything that C++ rules already do, but unfortunately that api is not yet finished (October 2017). I think the best tracking bug is https://github.com/bazelbuild/bazel/issues/1624.

Related

Cannot compile, error: cryptlib.h: No such file or directory

I've downloaded Crypto++ 7.0.0 from the official site, build a static library out of it, included cryptlib header with:
#include "cryptlib.h"
and when I try to compile my program with:
gcc main.cpp ./cryptopp700/libcryptopp.a
it throws at me errors like this:
main.cpp:2:10: fatal error: cryptlib.h: No such file or directory
#include "cryptlib.h"
^~~~~~~~~~~~
compilation terminated.
I also tried with:
-L. -llibcryptopp //while moving libcryptopp.a to the same directory main.cpp is
-L./cryptopp700 -llibcryptopp
so I started wondering if I was doing something wrong, but as I was checking out code examples with static libraries, everything seemed to be fine.
Help please.
Based on:
main.cpp:2:10: fatal error: cryptlib.h: No such file or directory
And:
gcc main.cpp ./cryptopp700/libcryptopp.a
Your directory structure looks like:
+- Project Folder
|
+- main.cpp
|
+- cryptopp700
|
+- cryltib.h
+- ...
+- libcryptopp.a
You should only need to add cryptopp700/ to your include header search path with -I:
g++ main.cpp -I ./cryptopp700 ./cryptopp700/libcryptopp.a
Note that you should also use g++ (the C++ compiler), not gcc (the C compiler).
You can also install the library since it has been built. By default it installs into /usr/local with:
skylake:cryptopp$ sudo make install
[sudo] password for jwalton:
install -m 644 *.h /usr/local/include/cryptopp
install -m 644 libcryptopp.a /usr/local/lib
install cryptest.exe /usr/local/bin
install -m 644 TestData/*.dat /usr/local/share/cryptopp/TestData
install -m 644 TestVectors/*.txt /usr/local/share/cryptopp/TestVectors
You can install into an alternate location using PREFIX:
skylake:cryptopp$ sudo make install PREFIX=/opt/local
install -m 644 *.h /opt/local/include/cryptopp
install -m 644 libcryptopp.a /opt/local/lib
install cryptest.exe /opt/local/bin
install -m 644 TestData/*.dat /opt/local/share/cryptopp/TestData
install -m 644 TestVectors/*.txt /opt/local/share/cryptopp/TestVectors
Then, you would change you compile and link command to something like:
g++ main.cpp -I /usr/local/include/cryptopp -o main.exe /usr/local/lib/libcryptopp.a
After an install like shown below, I normally tell folks to run the self tests. Unfortunately, the won't work if all you did was a make -j 4 or similar.
$ make -j 4
...
$ sudo make install
[sudo] password for jwalton:
install -m 644 *.h /usr/local/include/cryptopp
install -m 644 libcryptopp.a /usr/local/lib
install cryptest.exe /usr/local/bin
install -m 644 TestData/*.dat /usr/local/share/cryptopp/TestData
install -m 644 TestVectors/*.txt /usr/local/share/cryptopp/TestVectors
Here's the error you would get:
skylake:cryptopp$ cd /opt/local/bin/
skylake:bin$ ./cryptest.exe v
Using seed: 1544189072
Testing Settings...
passed: Your machine is little endian.
passed: Aligned data access.
passed: sizeof(byte) == 1
passed: sizeof(word16) == 2
passed: sizeof(word32) == 4
passed: sizeof(word64) == 8
passed: sizeof(word128) == 16
passed: sizeof(hword) == 4, sizeof(word) == 8, sizeof(dword) == 16
passed: cacheLineSize == 64
hasSSE2 == 1, hasSSSE3 == 1, hasSSE4.1 == 1, hasSSE4.2 == 1, hasAVX == 1, hasAVX2 == 1, hasAESNI == 1, hasCLMUL == 1, hasRDRAND == 1, hasRDSEED == 1, hasSHA == 0, isP4 == 0
...
SHA validation suite running...
Exception caught: Can not open file TestVectors/sha.txt for reading
My thinking is things should "just work" for you. You should not need to worry about CRYPTOPP_DATA_DIR for a common case. And you certainly should not have to RTFM to make the common case work. That tells me there's a defect in our engineering process.
We are going to fix that now: Issue 760, Make self-tests run after install by a typical user.
For me installing the development crypt library solved the issue:
apt-get install libcrypt-devel

"string.h" not found message in building qt app for iOS

I've recently updated Xcode to version 10.0 and after that when I try to build version for iOS I've the following problem.
1:04:17: Running steps for project Diasteca...
11:04:17: Starting: "/Users/belladellifabio/Qt/5.11.1/ios/bin/qmake" /Users/belladellifabio/Desktop/QtProjects/Diasteca/mqtt_test/mqtt_test.pro -spec macx-ios-clang CONFIG+=iphoneos CONFIG+=device CONFIG+=qml_debug
Project MESSAGE: This project is using private headers and will therefore be tied to this specific Qt module build version.
Project MESSAGE: Running this project against other versions of the Qt modules may crash at any arbitrary point.
Project MESSAGE: This is not a bug, but a result of using Qt internals. You have been warned!
11:04:18: The process "/Users/belladellifabio/Qt/5.11.1/ios/bin/qmake" exited normally.
11:04:18: Starting: "/usr/bin/make" qmake_all
make: Nothing to be done for `qmake_all'.
11:04:18: The process "/usr/bin/make" exited normally.
11:04:18: Starting: "/usr/bin/make"
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ -c -pipe -stdlib=libc++ -g -fPIC -std=gnu++11 -arch arm64 -arch x86_64 -Xarch_arm64 -miphoneos-version-min=12.0 -Xarch_arm64 -isysroot/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS11.3.sdk -Xarch_x86_64 -mios-simulator-version-min=12.0 -Xarch_x86_64 -isysroot/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator11.3.sdk -fobjc-nonfragile-abi -fobjc-legacy-dispatch -fembed-bitcode-marker -Wall -W -DQT_COMPILER_SUPPORTS_SSE2 -DMQTT_TEST_LIBRARY -DQT_DEPRECATED_WARNINGS -DQT_QML_DEBUG -DQT_NETWORK_LIB -DQT_CORE_LIB -I../../Diasteca/mqtt_test -I. -I../../../../Qt/5.11.1/ios/mkspecs/common/uikit -I../../../../Qt/5.11.1/ios/include -I../../../../Qt/5.11.1/ios/include/QtNetwork -I../../../../Qt/5.11.1/ios/include/QtCore/5.11.1 -I../../../../Qt/5.11.1/ios/include/QtCore/5.11.1/QtCore -I../../../../Qt/5.11.1/ios/include/QtCore -I. -I../../../../Qt/5.11.1/ios/mkspecs/macx-ios-clang -o qmqttclient.o ../../Diasteca/mqtt_test/qmqttclient.cpp
clang: warning: no such sysroot directory: '/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS11.3.sdk' [-Wmissing-sysroot]
clang: warning: no such sysroot directory: '/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator11.3.sdk' [-Wmissing-sysroot]
In file included from ../../Diasteca/mqtt_test/qmqttclient.cpp:30:
In file included from ../../Diasteca/mqtt_test/qmqttclient.h:33:
In file included from ../../Diasteca/mqtt_test/qmqttglobal.h:33:
In file included from ../../../../Qt/5.11.1/ios/include/QtCore/qglobal.h:47:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/utility:202:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/cstring:61:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/string.h:61:15: fatal error: 'string.h' file not found
Probably the real problem is not the file not found error, but is connected to the fact that qty tries to build the app using an SDK that is no more installed on the system. Is this a qt problem? How could I specify the version of iOS SDK to use to build the app? Is it possible?
Finally, I've found and delete .qmake.cache and .qmake.stash files. I've restart QtCreator and now it seems to work.
Qt stores SDK information somewhere deep in the build output and the .pro.user file.
Remove the user file (you might want to backup your user file in case you have custom build steps), the complete (shadow) build tree and modify your .pro file so that there is no such line as QMAKE_MAC_SDK = macosx10.13.
Then call qmake and build your project again, the inconsistency should be gone.
This occurs when the iOS SDK that Qt is expecting is different than the iOS SDK that you have installed. For instance Qt 5.13.1 expects iPhoneOS13.1.sdk but my Xcode currently has iPhoneOS13.2.sdk:
$ cd /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs
$ ls -l
total 0
drwxrwxr-x 7 root wheel 224 Nov 5 2019 iPhoneOS.sdk
lrwxr-xr-x 1 root wheel 12 Jan 15 2020 iPhoneOS13.2.sdk -> iPhoneOS.sdk
$ cd /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs
$ ls -l
total 0
drwxrwxr-x 8 root wheel 256 Jul 22 14:14 iPhoneSimulator.sdk
lrwxr-xr-x 1 root wheel 19 Jan 15 2020 iPhoneSimulator13.2.sdk -> iPhoneSimulator.sdk
To remedy this, we can get Qt to use the iPhoneOS13.2.sdk:
$ cd /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs
$ ls -l
total 0
drwxrwxr-x 7 root wheel 224 Nov 5 2019 iPhoneOS.sdk
lrwxr-xr-x 1 root wheel 12 Jan 15 2020 iPhoneOS13.2.sdk -> iPhoneOS.sdk
$ sudo ln -s iPhoneOS.sdk iPhoneOS13.1.sdk
$ ls -l
total 0
drwxrwxr-x 8 root wheel 256 Jul 22 14:20 iPhoneOS.sdk
lrwxr-xr-x 1 root wheel 12 Jul 22 14:20 iPhoneOS13.1.sdk -> iPhoneOS.sdk
lrwxr-xr-x 1 root wheel 12 Jan 15 2020 iPhoneOS13.2.sdk -> iPhoneOS.sdk
$ cd /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs
$ ls -l
total 0
drwxrwxr-x 8 root wheel 256 Jul 22 14:14 iPhoneSimulator.sdk
lrwxr-xr-x 1 root wheel 19 Jan 15 2020 iPhoneSimulator13.2.sdk -> iPhoneSimulator.sdk
$ sudo ln -s iPhoneSimulator.sdk iPhoneSimulator13.1.sdk
$ ls -l
total 0
drwxrwxr-x 8 root wheel 256 Jul 22 14:14 iPhoneSimulator.sdk
lrwxr-xr-x 1 root wheel 19 Jul 22 14:39 iPhoneSimulator13.1.sdk -> iPhoneSimulator.sdk
lrwxr-xr-x 1 root wheel 19 Jan 15 2020 iPhoneSimulator13.2.sdk -> iPhoneSimulator.sdk
I met a similar problem, because my xcode project was created by different XCode SDK, and it's generated by CMake, so I deleted the cache and solved the problem.

Unable to link dynamic library : Compiling through Xcode make

My project structure is as follows:
Project>src>main.cpp
The main.cpp calls methods which have a dependancy to a dynamic library (.dylib). In my /usr/local/bin the dynamic library has the name libgismo.dylib but it is an alias which points to libgismo.0.8.1.dylib
My make file is:
# Targets
SRCPATH = ./src
GISMOPATH = /usr/local/include/gismo
CXX = g++
INCLUDE = -I/usr/local/bin -I/usr/local/include -I$(GISMOPATH) -I/usr/local/lib
DYLD_LIBRARY_PATH = -L/usr/local/lib
LIBS = -libgismo
all: main
main : $(SRCPATH)/main.cpp
#$(CXX) $(INCLUDE) $(SRCPATH)/main.cpp -o main $(DYLD_LIBRARY_PATH) $(LIBS)
$(info Compiling main)
clean :
#rm main
But when I build it through Xcode the following error is generated:
ld: library not found for -libgismo.0
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [main] Error 1
Command /Applications/Xcode.app/Contents/Developer/usr/bin/make failed with exit code 2
The output to:
$ make -n
is
g++ -I/usr/local/bin -I/usr/local/include -I/usr/local/include/gismo -I/usr/local/lib ./src/main.cpp -o main -L/usr/local/lib/ -libgismo
AND
$ ls -l /usr/local/lib/*gismo*
is
-rw-r--r-- 1 root wheel 1337 May 14 11:35 /usr/local/lib/gismoConfig.cmake
-rw-r--r-- 1 root wheel 366 May 14 11:35 /usr/local/lib/gismoConfigVersion.cmake
-rw-r--r-- 1 root wheel 3900 May 14 11:34 /usr/local/lib/gismoUse.cmake
-rwxr-xr-x 1 root wheel 9195544 May 14 11:52 /usr/local/lib/libgismo.0.8.1.dylib
lrwxr-xr-x 1 root wheel 20 May 12 10:23 /usr/local/lib/libgismo.0.dylib -> libgismo.0.8.1.dylib
lrwxr-xr-x 1 root wheel 16 May 12 10:23 /usr/local/lib/libgismo.dylib -> libgismo.0.dylib
How do I fix this?
Thanks!

Error while running configure on nxlogs build

I'm attempting to build nxlog with some updated libraries:
Latest APR (1.5.2)
Non-Heartbleed vulnerable OpenSSL sources
PCRE 8.37
Zlib 1.2.8
After building all the dependencies I'm a little stuck on getting nxlogs to build, specifically I'm stuck on the step where I run ./configure
At first it couldn't find apr-1-config, so I added /local/apr/bin to the path.
Then it couldn't fine libapr-1 so I added /local/apr/lib to the path, this is where the problems started. When APR built there wasn't a "libapr-1" file in /local/apr/lib, only libapr-1.a, libapr-1.la, libapr-1.dll.a.
Did I build APR incorrectly?
I'm trying to build this on windows
List of steps to get where I am:
Install MINGW using MinGW Installation Manager
Add packages:
mingw-developer-toolkit
mingw-base
mingw-expat bin
mingw32-libexpat dev
msys-libopenssl dev
msys-automake
msys-autoconf
Setup msys fstab (c:/mingw /mingw)
Install Python (2.5)
Add Python and mingw to system path (C:\Python25;C:\MinGW\bin;C:\MinGW\msys\1.0\bin)
Get and build APR source (I could not get APR iconv to compile)
Download:
http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.11.tar.gz
http://mirror.nexcess.net/apache//apr/apr-1.5.2-win32-src.zip
http://mirror.nexcess.net/apache//apr/apr-util-1.5.4-win32-src.zip
http://sourceforge.net/projects/pcre/files/pcre/8.37/pcre-8.37.zip/download
http://zlib.net/zlib128.zip
Build:
Extract all files to c:\mingw\msys\1.0\src
Compile libiconv
cd libiconv-1.11
./configure CFLAGS="-O2 -s -mms-bitfields -march=i686" CXXFLAGS="-O2 -s -mms-bitfields -march=i686"
make && make install
Compile APR
cd apr
./buildconf
./configure CFLAGS="-O0 -s -mms-bitfields -march=i686" CXXFLAGS="-O0 -s -mms-bitfields -march=i686"
make && make install
cd ..
Compile APR-UTIL
cd apr-util-1.5.4
./buildconf --with-apr=/usr/src/apr-1.5.2
./configure CFLAGS="-O2 -s -mms-bitfields -march=i686" CXXFLAGS="-O2 -s -mms-bitfields -march=i686" --with-apr=/usr/src/apr-1.5.2
make && make install
cd ..
Compile PCRE
cd pcre-.37
./configure
make && make install
(make threw an error corrected with make clean, autoconf -i --force, started back at step 1)
cd ..
Compile ZLIB
cd zlib-1.2.8
make -f win32/Makefile.gcc
Compile nxlog
cd nxlog-ce-2.8.1248
./configure
This is where the problems began. First it couldn't find apr-1-config.
Fixed by adding /local/apr/bin to path.
Now it can't find libapr-1, adding /local/apr/lib to the path doesn't help. There is no libapr-1 file in the MinGW directory tree; thought I do see libapr-1.a libapr-1.la libapr.dll.a. Ideas? I assume this is supposed to be a script file to respond to queries about the library's interfaces?

Cross-compiling boost for Windows on Linux

I'm trying to create mingw binaries for boost on a Linux machine. The mingw compiler is present on my system as /usr/bin/i586-mingw32msvc-g++ and I have been able to create a simple HelloWorld.exe application.
Here is an exact list of my actions:
$ tar xvf boost_1_46_1.tar.gz
$ cd boost_1_46_1/
$ echo "using gcc : 4.4.4: i586-mingw32msvc-g++ ;" > user-config.jam
$ ./bootstrap.sh
$ ./bjam toolset=gcc target-os=windows
The result is this:
Building the Boost C++ Libraries.
...found 83 targets...
...updating 9 targets...
common.mkdir bin.v2
common.mkdir bin.v2/libs
common.mkdir bin.v2/libs/regex
common.mkdir bin.v2/libs/regex/build
common.mkdir bin.v2/libs/regex/build/gcc-mingw-4.4.4
common.mkdir bin.v2/libs/regex/build/gcc-mingw-4.4.4/debug
common.mkdir bin.v2/libs/regex/build/gcc-mingw-4.4.4/debug/target-os-windows
gcc.compile.c++ bin.v2/libs/regex/build/gcc-mingw-4.4.4/debug/target-os-windows/has_icu_test.o
In file included from /usr/include/unicode/pwin32.h:123,
from /usr/include/unicode/umachine.h:47,
from /usr/include/unicode/uversion.h:47,
from libs/regex/build/has_icu_test.cpp:12:
/usr/include/inttypes.h:290: warning: ISO C++ 1998 does not support ‘long long’
/usr/include/inttypes.h:291: warning: ISO C++ 1998 does not support ‘long long’
libs/regex/build/has_icu_test.cpp: In function ‘int main()’:
libs/regex/build/has_icu_test.cpp:24: warning: unused variable ‘c’
gcc.link bin.v2/libs/regex/build/gcc-mingw-4.4.4/debug/target-os-windows/has_icu.exe
/usr/lib/gcc/i586-mingw32msvc/4.4.4/../../../../i586-mingw32msvc/bin/ld: cannot find -licuuc
collect2: ld returned 1 exit status
"i586-mingw32msvc-g++" -L"/usr/bin" -L"/usr/lib" -Wl,-R -Wl,"/usr/bin" -Wl,-R -Wl,"/usr/lib" -Wl,-rpath-link -Wl,"/usr/bin" -Wl,-rpath-link -Wl,"/usr/lib" -o "bin.v2/libs/regex/build/gcc-mingw-4.4.4/debug/target-os-windows/has_icu.exe" -Wl,--start-group "bin.v2/libs/regex/build/gcc-mingw-4.4.4/debug/target-os-windows/has_icu_test.o" -Wl,-Bstatic -Wl,-Bdynamic -licuuc -licui18n -licudata -Wl,--end-group -g
...failed gcc.link bin.v2/libs/regex/build/gcc-mingw-4.4.4/debug/target-os-windows/has_icu.exe...
...failed updating 1 target...
...updated 8 targets...
Performing configuration checks
- has_icu builds : no
warning: Graph library does not contain MPI-based parallel components.
note: to enable them, add "using mpi ;" to your user-config.jam
...found 8 targets...
...updating 6 targets...
common.mkdir bin.v2/libs/math
common.mkdir bin.v2/libs/math/config
common.mkdir bin.v2/libs/math/config/gcc-mingw-4.4.4
common.mkdir bin.v2/libs/math/config/gcc-mingw-4.4.4/debug
common.mkdir bin.v2/libs/math/config/gcc-mingw-4.4.4/debug/target-os-windows
gcc.compile.c++ bin.v2/libs/math/config/gcc-mingw-4.4.4/debug/target-os-windows/has_gcc_visibility.o
cc1plus: warnings being treated as errors
libs/math/config/has_gcc_visibility.cpp: In function ‘int main()’:
libs/math/config/has_gcc_visibility.cpp:13: error: visibility attribute not supported in this configuration; ignored
"i586-mingw32msvc-g++" -ftemplate-depth-128 -O0 -fno-inline -Wall -g -Werror -fvisibility=hidden -DBOOST_ALL_NO_LIB=1 -I"." -c -o "bin.v2/libs/math/config/gcc-mingw-4.4.4/debug/target-os-windows/has_gcc_visibility.o" "libs/math/config/has_gcc_visibility.cpp"
...failed gcc.compile.c++ bin.v2/libs/math/config/gcc-mingw-4.4.4/debug/target-os-windows/has_gcc_visibility.o...
...failed updating 1 target...
...updated 5 targets...
- ../config//has_gcc_visibility builds : no
...found 46 targets...
...updating 1 target...
gcc.compile.c++ bin.v2/libs/math/config/gcc-mingw-4.4.4/debug/target-os-windows/has_long_double_support.o
...updated 1 target...
- ../config//has_long_double_support builds : yes
warning: skipping optional Message Passing Interface (MPI) library.
note: to enable MPI support, add "using mpi ;" to user-config.jam.
note: to suppress this message, pass "--without-mpi" to bjam.
note: otherwise, you can safely ignore this message.
************************************************************
Trying to build Boost.Thread with pthread support.
If you need pthread you should specify the paths.
You can specify them in site-config.jam, user-config.jam
or in the environment.
For example:
PTW32_INCLUDE=C:\Program Files\ptw32\Pre-built2\include
PTW32_LIB=C:\Program Files\ptw32\Pre-built2\lib
************************************************************
/home/francis/orig/boost_1_46_1/tools/build/v2/build/virtual-target.jam:1079: in virtual-target.register-actual-name from module virtual-target
error: Duplicate name of actual target: <pstage/lib>libboost_date_time.a
error: previous virtual target { common%common.copy-libboost_date_time.a.STATIC_LIB { gcc%gcc.archive-libboost_date_time.a.STATIC_LIB { gcc%gcc.compile.c++-gregorian/greg_month.o.OBJ { gregorian/greg_month.cpp.CPP } } { gcc%gcc.compile.c++-gregorian/greg_weekday.o.OBJ { gregorian/greg_weekday.cpp.CPP } } { gcc%gcc.compile.c++-gregorian/date_generators.o.OBJ { gregorian/date_generators.cpp.CPP } } } }
error: created from ./stage-proper
error: another virtual target { common%common.copy-libboost_date_time.a.STATIC_LIB { gcc%gcc.archive-libboost_date_time.a.STATIC_LIB { gcc%gcc.compile.c++-gregorian/greg_month.o.OBJ { gregorian/greg_month.cpp.CPP } } { gcc%gcc.compile.c++-gregorian/greg_weekday.o.OBJ { gregorian/greg_weekday.cpp.CPP } } { gcc%gcc.compile.c++-gregorian/date_generators.o.OBJ { gregorian/date_generators.cpp.CPP } } } }
error: created from ./stage-proper
error: added properties: <debug-symbols>off <define>NDEBUG <inlining>full <optimization>speed <runtime-debugging>off <variant>release
error: removed properties: <debug-symbols>on <inlining>off <optimization>off <runtime-debugging>on <variant>debug
/home/francis/orig/boost_1_46_1/tools/build/v2/build/virtual-target.jam:490: in actualize-no-scanner from module object(file-target)#3884
/home/francis/orig/boost_1_46_1/tools/build/v2/build/virtual-target.jam:135: in object(file-target)#3884.actualize from module object(file-target)#3884
/home/francis/orig/boost_1_46_1/tools/build/v2/build-system.jam:748: in load from module build-system
/home/francis/orig/boost_1_46_1/tools/build/v2/kernel/modules.jam:283: in import from module modules
/home/francis/orig/boost_1_46_1/tools/build/v2/kernel/bootstrap.jam:142: in boost-build from module
/home/francis/orig/boost_1_46_1/boost-build.jam:17: in module scope from module
It says libicu is not found on my system, but according to Synaptic Package Manage I have the libicu-dev package installed.
I'm not sure how to get it right. Can anyone help?
Update 1
Following #Luke's recoommendation I now gcc-mingw toolset. So now my build instructions look like this:
tar xvf boost_1_46_1.tar.gz
cd boost_1_46_1/
echo "using gcc : 4.4.4: i586-mingw32msvc-g++ ;" > user-config.jam
./bootstrap.sh
./bjam toolset=gcc-mingw target-os=windows
Which leads to the following errors:
error: toolset gcc initialization:
error: version 'mingw' requested but 'g++-mingw' not found and version '4.4.5' of default 'g++' does not match
error: initialized from
/home/francis/orig/boost-mingw/boost_1_46_1/tools/build/v2/build/toolset.jam:38: in toolset.using from module toolset
/home/francis/orig/boost-mingw/boost_1_46_1/tools/build/v2/build-system.jam:481: in process-explicit-toolset-requests from module build-system
/home/francis/orig/boost-mingw/boost_1_46_1/tools/build/v2/build-system.jam:561: in load from module build-system
/home/francis/orig/boost-mingw/boost_1_46_1/tools/build/v2/kernel/modules.jam:283: in import from module modules
/home/francis/orig/boost-mingw/boost_1_46_1/tools/build/v2/kernel/bootstrap.jam:142: in boost-build from module
/home/francis/orig/boost-mingw/boost_1_46_1/boost-build.jam:17: in module scope from module
Update 2
I have also tried specifying gcc-mingw in the user-config.jam file. Then my build instructions look like this:
tar xvf boost_1_46_1.tar.gz
cd boost_1_46_1/
echo "using gcc-mingw : 4.4.4: i586-mingw32msvc-g++ ;" > user-config.jam
./bootstrap.sh
./bjam toolset=gcc-mingw target-os=windows
Which leads to:
error: version 'mingw' requested but 'g++-mingw' not found and version '4.4.5' of default 'g++' does not match
Update 3
Specifying g++-mingw in the user-config.jam file:
using g++-mingw : 4.4.4: i586-mingw32msvc-g++ ;
...leads to the same error.
I got similar error messages. Eventually I was able to compile it using exactly the following commands:
$ echo "using gcc : : i686-w64-mingw32-g++ ;" > user-config.jam
$ ./bootstrap.sh
$ ./b2 --user-config=user-config.jam toolset=gcc-mingw target-os=windows release
I believe your problem is that you don't specify the "--user-config=user-config.jam" parameter. The next problem I encountered was that there will be a name conflict unless I specify either debug or release build (--layout=tagged or --layout=versioned might work also).
Cross-compiling boost 1.72.0 for Windows on Ubuntu 18.04
Install MinGW
$ sudo apt install mingw-w64 mingw-w64-tools
$ sudo update-alternatives --set i686-w64-mingw32-g++ /usr/bin/i686-w64-mingw32-g++-posix
$ sudo update-alternatives --set i686-w64-mingw32-gcc /usr/bin/i686-w64-mingw32-gcc-posix
$ sudo update-alternatives --set x86_64-w64-mingw32-g++ /usr/bin/x86_64-w64-mingw32-g++-posix
$ sudo update-alternatives --set x86_64-w64-mingw32-gcc /usr/bin/x86_64-w64-mingw32-gcc-posix
32-bit Compilation (install path: ./boost-x86)
$ echo "using gcc : : i686-w64-mingw32-g++ ;" > user-config.jam
$ ./bootstrap.sh
$ ./b2 --user-config=./user-config.jam --prefix=./boost-x86 target-os=windows address-model=32 variant=release install
64-bit Compilation (install path: ./boost-x64)
$ echo "using gcc : : x86_64-w64-mingw32-g++ ;" > user-config.jam
$ ./bootstrap.sh
$ ./b2 --user-config=./user-config.jam --prefix=./boost-x64 target-os=windows address-model=64 variant=release install
I had some difficulty with this too, but it seems to be working for me now. To be clear, I'm cross compiling on Linux for Windows.
in user-config.jam:
using gcc : mingw32 : i686-w64-mingw32-g++ ;
Note that the second term "mingw32" is an arbitrary "version" tag. The toolset flag combines the compiler name and the version name w/ a dash. So, in my case, gcc-mingw32. The third term is what actually gets invoked ("i686-w64-mingw32-g++"). Obviously your version of mingw's compiler may have a different name.
Here is how I invoked bjam:
./b2 toolset=gcc-mingw32 target-os=windows threadapi=win32 --build-type=complete --prefix=/usr/x86_64-w64-mingw32/local --layout=tagged --without-python -sNO_BZIP2=1 -sNO_ZLIB=1
I got all the interesting flags from Congelli501's answer. But didn't bother with the directory of links approach.
This is the commands I use. I have tested them for boost 1.46 and 1.49.
To begin, create links to the compiler inside /usr/i686-w64-mingw32/bin. You can run this script :
#!/bin/bash
binDir="/usr/bin"
destDir="/usr/i686-w64-mingw32/bin"
cd "$binDir"
mkdir -p "$destDir"
for name in $(ls i686-w64-mingw32*); do
newName=$(echo "$name" | sed -e "s/i686-w64-mingw32-\(.\?\)/\1/")
if [ -f "$destDir/$newName" ]; then
rm "$destDir/$newName"
fi
ln -s "$binDir/$name" "$destDir/$newName"
done
Then, install bjam. On ubuntu / debian, it is included in the package "libboost1.48-dev"
apt-get install libboost1.48-dev
To finish, become root and run
env PATH=/usr/i686-w64-mingw32/bin:$PATH bjam toolset=gcc target-os=windows variant=release threading=multi threadapi=win32 link=static --prefix=/usr/i686-w64-mingw32 -j 4 --without-mpi --without-python -sNO_BZIP2=1 -sNO_ZLIB=1 --layout=tagged install
Done !
According to this it looks like you should be using the toolset=gcc-mingw. You have toolset=gcc.
As Luke already mentioned, toolset=gcc-mingw will certainly help.
Your libicu-dev is 99% sure the linux library headers, which is not for mingw. You'll either have to build it yourself or get it from someplace (could be your distribution, otherwise you'll need to build it from source)
I had same problem. Try specifying only a single build variant (i.e., add "variant=Release link=shared runtime-link=shared")