How to build tests using boost.test on mingw64? - boost

I'm trying to write some code using the boost libraries on windows 10. To build the application I have chosen mingw64, which I have installed together with MSYS2.
After downloading and installing the boost libraries(1.76), I tried this example code (https://www.boost.org/doc/libs/1_76_0/more/getting_started/windows.html#build-a-simple-program-using-boost), which I built fine using this command:
g++ .\example.cpp -o test.exe -IC:\Users\Benelli\BoostLib\boost_1_76_0\boost_1_76_0
This example works on my system so I assumed that the boost libraries are installed correctly, although I did not build them, but I understood that the boost.test libary can be used as "header only".
I written a simple code following this tutorial:https://www.boost.org/doc/libs/1_76_0/more/getting_started/windows.html#build-a-simple-program-using-boost.
#define BOOST_TEST_MODULE const_string test
#include <boost/test/unit_test.hpp>
This code does not compile and I really do not get why. Is the boost.test library really "header_only"?
The command I used to build it was:
g++ .\boost_test_example.cpp -o boost_test.exe -IC:\Users\Benelli\BoostLib\boost_1_76_0\boost_1_76_0
Which gives this error message:

For the header only:
I think you need to use boost/test/included/unit_test.hpp as per the boost docs at https://www.boost.org/doc/libs/1_69_0/libs/test/doc/html/boost_test/adv_scenarios/single_header_customizations/multiple_translation_units.html
I had a similar winMain error and had to the define for BOOST_TEST_DYN_LINK to the top of the code (when i was linking against the libraries).
#define BOOST_TEST_DYN_LINK
#define BOOST_TEST_MODULE const_string test
#include <boost/test/unit_test.hpp>
When not using the header only for the undefined references link with the boost test library, eg -LC:/msys64/mingw64/lib -lboost_unit_test_framework-mt.

Related

Using boost in console programming environment with mingw g++ compiler

I installed boost following instructions here: https://phylogeny.uconn.edu/tutorial-v2/part-1-ide-project-v2/setting-up-the-boost-c-library-v2/#
works in Visual Studio, but doesn't work when compiling using mingw g++ in windows cmd.
Editor is vim.
source code is like:
#include <boost/algorithm/string.hpp>
...
compiling like this:
> g++ -o test test.cpp
test.cpp:7:10: fatal error: boost/algorithm/string.hpp: No such file or directory
#include <boost/algorithm/string.hpp>
How can I make my mingw g++ available for boost?
You used the config from the page:
import option ;
using msvc ;
option.set keep-going : false ;
libraries = --with-program_options --with-regex --with-filesystem --with-system ;
using msvc should probably tell you something. It uses the MSVC toolchain. Because these are not interoperable (different C++ runtime libraries, for starters, different ABI likely), you can't link to those libraries.
Header Only
If, like the code you showed, you only require headers, then that is no issue, just add the include path to your compiler flags, as the tutorial also told you:
So either typing command line options directly:
g++ -I C:\boost_1_65_0
Or adding to a variable in your build script(s), like Makefile:
CPPFLAGS+=-I C:\boost_1_65_0
Or CMake:
INCLUDE_DIRECTORIES(C:\boost_1_65_0)
With Linking
To use pre-built shared libraries, you need to build different versions for mingw. See e.g. these steps: https://gist.github.com/zrsmithson/0b72e0cb58d0cb946fc48b5c88511da8
I installed from that last week (context) and it worked fine. (I also ended up going no-IDE with Vim, though VsCode was ok as well)
Check that it is using the mingw toolchain (e.g. mgw81) which also means that mgw81 shoud be part of the library filenames. Following just that tutorial already gives you this, but your previously existing configs might interfere if you're not careful.

Yocto meta-toolchain fatal error: stdio.h: No such file or directory

Question: How to add the standard library to arm-fslc-linux-gnueabi-gcc
Background:
I just had bitbake compile the meta-toolchain in the Yocto project.
I then installed the resulting SDK-toolchain
$
./build/tmp/deploy/sdk/fslc-framebuffer-glibc-x86_64-meta-toolchain-armv7at2hf-neon-toolchain-2.4.2.sh
which then installed the SDK-toolchain in /opt/fslc-framebuffer/2.4.2/
I can then easily run the executable to source the correct environment variables.
$
./opt/fslc-framebuffer/2.4.2/environment-setup-armv7at2hf-neon-fslc-linux-gnueabi
I now have access to the cross-compiler arm-fslc-linux-gnueabi-gcc
So far so good...
I then downloaded the barebone SDK from NXP here.
It's a great piece of work, but it might be somewhat outdated. First unzip the file, and then follow steps within the SDK readme.pdf.
Following the readme.pdf i do the following: To build the SDK, use the ./tools/build_sdk command from the root folder. I get multiple error but they are all related to the standard library such as:
iMX6_Platform_SDK/sdk/drivers/accelerometer/src/mma8451.c:31:10: fatal error: string.h: No such file or directory #include <string.h>
iMX6_Platform_SDK/sdk/include/sdk.h:40:10: fatal error: stdio.h: No such file or directory #include <stdio.h>
So how do I solve this? Do I cross compile the standard library or do I get the binary some other place?
SDK build by yocto is little bit different than normal arm toolchain.
I believe you used
arm-fslc-linux-gnueabi-gcc hello.c
but actually you need to use Makefiles or Macros like below,
${CC} hello.c -o hello
Write this directly into your terminal or put it into a makefile.

CUDA error with Boost make_shared.hpp? [duplicate]

I'm trying to integrate CUDA to an existing aplication wich uses boost::spirit.
Isolating the problem, I've found out that the following code does not copile with nvcc:
main.cu:
#include <boost/spirit/include/qi.hpp>
int main(){
exit(0);
}
Compiling with nvcc -o cudaTest main.cu I get a lot of errors that can be seen here.
But if I change the filename to main.cpp, and compile again using nvcc, it works. What is happening here and how can I fix it?
nvcc sometimes has trouble compiling complex template code such as is found in Boost, even if the code is only used in __host__ functions.
When a file's extension is .cpp, nvcc performs no parsing itself and instead forwards the code to the host compiler, which is why you observe different behavior depending on the file extension.
If possible, try to quarantine code which depends on Boost into .cpp files which needn't be parsed by nvcc.
I'd also make sure to try the nvcc which ships with the recent CUDA 4.1. nvcc's template support improves with each release.

boost test on windows with mingw compiler error: putenv not declared

I'm trying to compile a library on windows with mingw, that uses boost.
I compiled boost with:
bootstrap mingw
b2 toolset=gcc
After that I build the library with cmake and mingw.
Building the dll itself works fine, but when I try to build the tests, I get:
C:/boost/boost_1_55_0/boost/test/utils/runtime/config.hpp:95:51: error: 'putenv'
was not declared in this scope
putenv( const_cast<char*>( fs.str().c_str() ) );
So the error comes from a boost header and I have no idea how to fix that.
The repo of what I'm trying to build: https://github.com/linges/daestruct
It uses c99 and c++11.
This seems to be a bug in boost. It has been happened to others, too:
https://github.com/BoostGSoC/boost.afio/commit/1b06855b6e20a01a3c4461c6d2d54e16eb3c8e21
The solution (or better: workaround) is to add the following lines before the inclusion of boost::test:
#ifdef __MINGW32__
// Mingw doesn't define putenv() needed by Boost.Test
extern int putenv(char*);
#endif

Compiling openCV 2.3.1 programs with MinGW gcc/g++ on Windows 7 64bit

For a week I've been struggling with compiling openCV programs. I've tried everything I could possibly find on the internet.
What I did is: I've downloaded OpenCV-2.3.1-win-superpack.exe and followed this official installation guide.
In the CMake (gui) my source was: D:\opencv and build destination was: C:\opencv.
I've also added C:\opencv\install\bin;C:\opencv\bin to my system's PATH variable.
What I want is to compile openCV programs on my Windows OS using MinGW's gcc/g++ compilers.
I've tried various gcc/g++ parameters that I've found on the internet and days playing with the -I and -L options the compiler can never find the openCV functions or structures.
What I am trying to compile:
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <cv.h>
#include <highgui.h>
int main(int argc, char *argv[])
{
// Nothing but create a window
cvNamedWindow("mainWin", CV_WINDOW_AUTOSIZE);
cvMoveWindow("mainWin", 100, 100);
cvWaitKey(0);
return 0;
}
Error:
Input:
gcc test.c -o test -I"C:\opencv\install\include" -I"C:\opencv\install\include\opencv" -L"C:\opencv\install\bin"
Output:
...\ccK4MfHv.o:test.c:(.text+0xa0b): undefined reference to `cvFree_'
Or with g++:
Input:
g++ test.c -o test -I"C:\opencv\install\include" -I"C:\opencv\install\include\opencv" -L"C:\opencv\install\bin"
Output:
...\ccXCTKa1.o:test.c:(.text+0x1e): undefined reference to `cvNamedWindow'
Side note: trying to compile in VS2005 I get the same error.
Thank you for your time!
In case someone else needs to solve this issue, here's how I got the posted OpenCV/HighGUI sample code to compile in Windows 7 x64 using MinGW, MSYS, and CMake:
build OpenCV from source using MinGW/MSYS/CMake. This is because I could not get the MinGW compiled version in the OpenCV-win-SuperPack to link properly in MinGW/MSYS/Windows 7 x64.
For full reference, here's how I compiled OpenCV:
make sure you have an up-to-date CMake (v2.6 or later) and MinGW (with GCC, G++, and MSYS options) installed
if you want the new Qt-based OpenCV HighGUI front-end, you will need to install Qt 4 (SDK).
download a OpenCV source/superpack version 2.2 or later (I used OpenCV-2.3.1-win-superpack.exe)
unzip the contents to [OPENCV_SOURCE_DIR] (I put it in C:/opencv, so there should be a file at C:/opencv/README for example)
create a [OPENCV_BUILD_DIR] directory elsewhere (I used C:/opencv/build/mingw)
use the CMake-GUI tool, specify the source directory as [OPENCV_SOURCE_DIR], the build directory as [OPENCV_BUILD_DIR], and click "Configure".
you may wish/need to go tweak the options (e.g. I ticked "Qt" and "Qt-OpenGL" entries, then clicked "Configure" again, then had to provide the path to the qmake executable)
once you have finished configuring OpenCV, click "Generate"
in a MSYS terminal, browse to [OPENCV_BUILD_DIR], and run "make" to build the code (this may take a while)
once the has been built properly, run "make install", which collects the built code/libraries/include dirs into [OPENCV_BUILD_DIR]/install folder (or a different folder if you changed the corresponding option when using the CMake-GUI tool)
add [OPENCV_BUILD_DIR]/install/bin folder to the PATH environmental variable. If you do not know how to do this, then I'd recommend using the Path Editor GUI tool.
if you end up using Qt, you will also need to put the bin folder of Qt SDK in the PATH environmental variable. This is the folder that includes qmake.exe.
put the following sample code into a file called test.c. I modified the includes slightly to make them compatible with OpenCV v2.2 and above.
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <opencv/cv.h>
#include <opencv/highgui.h>
int main(int argc, char *argv[])
{
// Nothing but create a window
cvNamedWindow("mainWin", CV_WINDOW_AUTOSIZE);
cvMoveWindow("mainWin", 100, 100);
cvWaitKey(0);
return 0;
}
in a MSYS terminal, browse to the folder where you put test.c, and run:
gcc -o test -I"[OPENCV_BUILD_DIR]/install/include" test.c \
-L"[OPENCV_BUILD_DIR]/install/lib" \
-lopencv_core[OPENCV_VERSION] \
-lopencv_imgproc[OPENCV_VERSION] \
-lopencv_highgui[OPENCV_VERSION]
So in my case:
gcc -o test -I"/c/opencv/build/mingw/install/include" test.c \
-L"/c/opencv/build/mingw/install/lib" \
-lopencv_core231
-lopencv_imgproc231
-lopencv_highgui231
Path Editor: http://www.redfernplace.com/software-projects/patheditor/
You have the directory, C:\opencv\install\bin, to locate libraries on the gcc/g++ command line, but I think you'll also need to specify the libraries to use as linker inputs as well. I'm not sure what libraries are part of the OpenCV distribution, but going by the example on the instruction page you linked to, one might be:
-lopencv_calib3d220.dll
You'll probably have to add one or more other ones (that follow the name pattern lib*.a in the C:\opencv\install\bin directory - or maybe some other lib directory that you should be passing in a -L option).

Resources