Error building boost with MinGW - c++

I tried to build boost library using the MinGW's GCC version that comes with CodeBLocks (gccc v5.1) and i have the bin folder in the PATH. When i run
boostrap.bat mingw
or
boostrap.bat gcc
i get
execnt.c: In function 'try_wait_callback':
execnt.c:833:5: warning: implicit declaration of function 'UnregisterWait' [-Wimplicit-function-declaration]
UnregisterWait( slot->wait_handle );
Reading a litte someone told me that my gcc version doesn't work to build boost so then i downloaded the last MinGW-w64 and copy its bin folder content into the MinGW's bin folder trying to "cheat"
if i do
gcc -v
i can see i have the version 7.3
Now it throws me this error:
gcc: error: CreateProcess: No such file or directory

You should use MinGW-w64, without the step "copy its bin folder content into the MinGW" !
You want to avoid using the pre-fork MinGW entirely. Download and install MinGW-w64 again and , if you want, add it to Code::Blocks.
Note that there are some sites providing MinGW-w64 and Boost bundles.

I had the same problem with MinGW provided with Code::Block. So I have to add to recomendations important details.
To build Boost.build tool:
After installation of minGW-w64 in NEW directory you need to delete entry of old MinGW\bin directory from PATH environment variable and add new entry with something like "C:\MinGW-w64\bin" entry.
By some reason starting commands in command line under user or administrator didn't work as supposed in Boost documentation, but if start terminal from shortcut provided by MinGW-w64 - commands of Boost can finish building. (Command "bootstrap.bat gcc")
Then Boost documentation recomends "b2 install --prefix=PREFIX" but I had to add parameter like "b2 install --prefix=PREFIX toolset=gcc" also in terminal started from MinGW-w64 shortcut.
Since I wanted to use MinGW32 of Code::Blocks in my projects (for other compatibility reasons), again I had to skip MinGW-w64 from availability (I had just renamed dir of MinGW-w64, you can delete entry from PATH) and to restore MinGW32 entry in PATH variable. Also I added Boost build tool "bin" dir into PATH.
So I had got Boost.Build tool ready to use (builded by MinGW-w64 compiler)
To build Boost libraries' binaries:
Then I started terminal under administrator, changed dir to boost root directory and then use the last command like "b2 --build-dir=build-directory toolset=gcc --build-type=complete stage" (where build-directory is of your choice)
And at last I'd got the result:
...failed updating 1334 targets...
...skipped 732 targets...
...updated 2873 targets...
Where I could find necessary for me files of Boost filesystem like
libboost_filesystem-mgw51-mt-x32-1_67.dll
libboost_filesystem-mgw51-mt-s-x32-1_67.a
libboost_filesystem-mgw51-mt-x32-1_67.a
etc.
I didn't test them yet, but this can help to others to build Boost.

Related

Boost with Qt Creator

I was trying to use boost/filesystem in my C++ project made with QtCreator.
The problem was that when building, I got the following error:
"error: undefined reference to `boost::system::generic_category()'"
To use boost, I had performed the following actions:
download boost library boost_1_73_0.7z file
unzip it in my computer (under D:\Development\Boost)
in .pro file, I have added the following option
INCLUDEPATH += D:/Development/Boost
in my .cpp file, I have added the following include
#include "boost/filesystem.hpp"
At this point, when compiling, I had the following error in Qt creator IDE
"error: undefined reference to `boost::system::generic_category()'"
The root cause is the following : FileSystem needs to be built. Therefore, I have built this boost library by :
adding gcc and g++ to the path variable (it is succesful as I could call 'g++' and 'gcc' from the command prompt).
opening Qt command prompt (I used Qt 5.15.0 (MinGW 73.0 64-bit) ) and by navigating to the repository where boost is installed.
executing the following command in the command prompt in the directory (D:\Development\Boost): bootstrap gcc
executing the following command in the command prompt in the directory where I had unzipped Boost: b2 toolset=gcc link=shared threading=multi --build-type=complete stage. This action has created a the directory D:\develoment\Boost\Stage\lib with all the dll, including 'libboost_filesystem-mgw8-mt-d-x64-1_73.dll'.
Now it's time to link the library in Qt creator. I have thus added the following in my .pro file:
LIBS += -LD:/Development/Boost/stage/lib libboost_filesystem-mgw8-mt-d-x64-1_73
When compiling, the error is gone.
Thanks for your help.
Gatien
As #drescherjm commented, you need to build the boost libraries.
They are not in the D:/Development/Boost/libs directory.
You appear to be using Windows and have boost installed on your "D:" drive.
I assume your using the MinGw compiler that comes with Qt Creator, not Visual Studio.
To build boost with MinGw, first open the relevant Qt Command prompt, e.g. Qt 5.12.3 (MinGW 7.3.0 64-bit) and type the following:
D:
cd \Development\Boost
bootstrap.bat gcc
b2 toolset=gcc link=shared threading=multi --build-type=complete stage
This will build the MinGw boost libraries in your directory: D:\Development\Boost\stage\lib.
Then change the link command to:
LIBS += -LD:/Development/Boost/stage/lib -l boost_system-mgw73-mt-x64-d-1_66
Note: the precise name of the boost_system library depends upon how boost named it in your version.
See Boost Getting Started on Windows: library naming. the answer here: mingw-w64 cannot find -lboost_filesystem and the filenames you built in the D:\Development\Boost\stage\lib directory.

Clion "Cannot load CMake project: CMake executable is incorrect" issue

I ran into a problem while trying to use Clion.
I imported a project, yet all off the headers and .cpp files are greyed out. The error shown is as in the title: "Cannot load CMake project: CMake executable is incorrect".Here is a screenshot of it.
It's worth noting that I'm working with kubuntu and have downloaded all of the following: gcc, g++, make, cmake, gdb.
I would love some help with solving this problem so I could start working with Clion.
Thanks in advance.
I just ran into this. Deleting the project's .idea directory and having clion recreate it fixed the issue for me.
Clion also reported that Bundled Cmake does not work in this enviroment
And when setting the actual path to the cmake binary it said it wasn't there when it was.
make a c executable project.
go to file->settings
Look for a setting where you can configure the path of Cmake on your system (maybe /usr/bin/cmake).
Clion hasn't found cmake executable
first case cmake isn't installed :
1.1. ubuntu : sudo apt-get install cmake
1.2. Go to Settings->Build,Execution,Deployement-> Toolchains:
set cmake executable to custom , and type : which cmake in your console
set field right to custom to dir of cmake
do same thing for gdb the apply
second case cmake is install then go to (1.2)
I am using WSL (wsl2 to be correct) and I had the same issue. Somehow CLion seems to have a problem with /usr/bin/cmake only being a link to the real cmake file. So to resolve this, follow each link till you hit the location of the executable
for windows users being new to linux:
which cmake (most probably shows /usr/bin/cmake)
cd /usr/bin/cmake
ls -la | grep cmake (shows something like 20 Mar 26 09:54 cmake -> /opt/cmake/bin/cmake)
do this till there is no link anymore
pass this path to clion
I already added this as a bug: https://youtrack.jetbrains.com/issue/CPP-20644

How to install LAPACK for MSVS 2010 on windows?

I am using the ITPP library (IT++ library) for one of my projects. For using the eigen_sym() function of this library, it asks for installing the LAPACK. I tried the direct prebuilt libraries for Windows but still get the error. Finally on the following site:
http://icl.cs.utk.edu/lapack-for-windows/lapack/#libraries
I found a solution under "Build Instructions to create LAPACK and LAPACKE 3.5.0 dlls for Windows with MinGW" that might work. I did steps 1 to 5 but got stuck 6 onwards.
My destination of the cmake build is E:/LAPACK
I got an error while in the cmd prompt while entering:
cd E:/LAPACK 3.5.0 >Enter
C:/MinGW/bin/mingw32-make.exe >Enter
i'm getting
mingw32-make.exe> No targets specified and no make file found. Stop.
Can someone explain the step 6 onwards in detail and tell me where i'm going wrong?
I finally want to get the .dll and .lib files.
I was able to build LAPACK 3.5 for windows using mingw and pretty much the build guide from the LAPACK page. Using the following steps
Download lapack.tgz from here http://netlib.org/lapack/lapack.tgz
Extract to a folder. I used 7zip file manager to extract the tarball to x:/Other/test
Install mingw32. I used this: http://www.mingw.org/download/installer and I selected and installed mingw32-developer-toolkit + mingw32-base + mingw32-gfortran + mingw32-gcc-g++ + msys-base
Open a command prompt
Append mingw to your path
path=C:/Mingw/bin;%PATH%
change directory to the location you extracted lapack: For me this was X:\Other\Test\lapack-3.5.0 so the command I typed was the following (your path will be different):
C:\Users\jdrescher>x:
X:>cd Other\Test\lapack-3.5.0
X:\Other\Test\lapack-3.5.0>
make a folder for your build. I used build
X:\Other\Test\lapack-3.5.0>mkdir build
then change directory to the build folder
X:\Other\Test\lapack-3.5.0>cd build
X:\Other\Test\lapack-3.5.0\build>
Now configure with CMake
X:\Other\Test\lapack-3.5.0\build>cmake -G "MinGW Makefiles" -D BUILD_SHARED_LIBS=ON -D CMAKE_GNUtoMS=ON ..
Now use gnu make to build LAPACK
X:\Other\Test\lapack-3.5.0\build>c:\MinGW\bin\mingw32-make.exe
Note: This step will take several minutes.
After the above steps completed 100% with no errors, I have the following dlls in the build\bin folder: libblas.dll, liblapack.dll, libtmglib.dll
Also the following libraries, and exp files in the build\lib folder: libblas.exp, libblas.lib, liblapack.exp, liblapack.lib, libtmglib.exp and libtmglib.lib.

Boost on windows with codeblocks - error: undefined reference to boost

Tons of these errors are popping up whenever I try to use boost in windows with codeblocks. On linux it works fine.
Even though I did add the boost .lib files and the include path to the GCC compiler in codeblocks.
I first compiled using bootstrap.bat + b2.exe but apperently that's wrong. A user in another forum said he fixed it but when I try his method I get:
So to clarify; what I did was:
. Add "C:\Program Files (x86)\CodeBlocks\MinGW\bin" to PATH
. Run bootstrap.bat which makes bjam.exe
. Run cmd.exe, cd to boost folder, enter bjam --build-dir=C:\boost --build-type=complete gcc stage
But then I get that error.
Why does compiling/using C++ libraries on windows always net these kind of errors that take hours to solve, while on linux it's nearly always flawless -.-
Who knows how to fix this one?
The technique that I use is as follows:
Set up the PATH environmental variable to include the bin directory of your GCC installation.
Extract boost somewhere.
Open a comand prompt and cd into the root of boost (the folder named boost_x_xx_x which has boost, doc, libs etc... subdirectories).
To compile boost, run:
bootstrap.bat
b2 toolset=gcc variant=release link=static threading=multi install
This will install boost to C:\Boost. If you want to install it elsewhere use the --build-dir= option when running b2.

How to compile googletest on windows using mingw with msys?

My need is simple. I have to compile and use googletest on windows using MinGW with msys. Has anyone some experience doing this?
Thanks for answers.
It took me some time but I figured it out. Here is the guide for anyone who face the same problem.
To be able to compile GoogleTest on Windows follow this instructions:
I assume you have MinGW with MSYS istalled.
Download and install CMake from the official site http://www.cmake.org/. Use the Win32 installer
version. Once you have completed the installation process copy executable files from
"xxx/CMake/bin" to "xxx/MinWG/bin".
Download and install Python from http://www.python.org/. Again, the Windows installer does the job
fine.
Once you have completed the installation process copy the "python.exe"
form python folder to
"xxx/MinWG/bin".
Download the latest stable GoogleTest from http://code.google.com/p/googletest/ and unpack it into some folder.
Run MSYS terminal and execute following commands.
cd xxx/gtest-x.x.x
cmake -G "MSYS Makefiles"
make
If you have compilation errors from pthread follow these instructions.
Copy the include folder "xxx/gtest-x.x.x/include" into your MinGW gcc include.
Copy the library files "xxx/gtest-x.x.x/*.a" into your MinGW gcc lib.
When you compile tests add "-lgtest" parameter to gcc.
EDIT
Commentators are right. The coping of executables worked for me but generaly it is not a good practice. Try to use a symbolic link instead.
To build libgtest.a without cmake/python, but only using mingw make, gtest now has a 'make' folder with a plain old makefile in it.
Make sure, mingw\bin is in the path (try running 'g++' or something).
Enter the gtest 'googletest\make' folder and run 'make'.
To test, run 'sample1_unittest' (gtest sample test output should appear).
To generate the library 'libgtest.a', run 'ar -rv libgtest.a gtest-all.o'
The library created is a full static library with no dll's generated.
That should be all.
By the way, this also works for building googlemock, just enter the googlemock folder instead of googletest, and follow the same procedure.
The question was asked in 2011 and answer with most votes is also answered the same year. So, a fresh answer would improve the question effectiveness.
Tools You need & I tested with:
Mingw64 8.0.2
GoogleTest GitHUb Source Code repo branch 1.10.0
CMake 3.20.4
and Windows10
Steps
Install the mingw64 by double clicking and chose the path which does
not have space between directory names e.g. "Program Files"
Open settings of the windows and then search environment variables
and oepn the dialog box to edit the Path environment variable
Add the mingw64/bin directory name in the Windows Path Environment
variable e.g. C:\Users[USERNAME]\mingw64\bin (replace [USERNAME]
with your username e.g. Michael or Lee etc)
Install CMake. It is double click install procedure. Make sure, its
bin directory path is added in the Path Environment Variable.
It would be installed in C:/Program Files/...
Download GoogleTest repo extract it and create a build directory
inside the extracted directory.
Execute the following commands
$ cd build
$ cmake .. -G "MinGW Makefiles"
$ mingw32-make.exe
Copy the four static libraries(*.a) from build directory
[ex: C:\Users[USERNAME]\sourcecodes\googletest-master\build\lib]
into lib of MingW64
[ex: C:\Users[USERNAME]\mingw64\x86_64-w64-mingw32\lib]
Go to the GoogleTest extracted repo, navigate to
[ex
C:\Users[USERNAME]\sourcecodes\googletest-master\googletest\include\gtest]
Copy that whole gtest directory and copy to the folder
C:\Users[USERNAME]\mingw64\lib\gcc\x86_64-w64-mingw32\8.1.0\include
You are done to go. You can build and link Googltest with your C++ project. I also paste a CMakelists.txt sample
cmake_minimum_required(VERSION 3.12)
project(ProjectName VERSION 1.0.0 LANGUAGES CXX)
include_directories(include)
set(SOURCES src/library.cpp include/library.h)
add_executable(libabc ${SOURCES})
#############
## Testing ##
#############
enable_testing()
find_library(GTest gtest)
add_executable (unitTest test/unit_test.cpp)
target_link_libraries (unitTest gtest gtest_main)
add_test(AllFactTest unitTest)
I hope it would work.
From the README of https://github.com/google/googletest/tree/master/googletest
:
When building Google Test as a standalone project, the typical workflow starts
with:
mkdir mybuild # Create a directory to hold the build output.
cd mybuild
cmake ${GTEST_DIR} # Generate native build scripts.
If you want to build Google Test's samples, you should replace the last command
with
cmake -Dgtest_build_samples=ON ${GTEST_DIR}
As alternative it is also possible to build googletest using the usual MSYS/Mingw make.
So here is my alternative way:
Make sure MSys/MingW is installed on your Windows and the PATH environment is set to it
Open a cmd window - you can set the PATH explicitly here as well
CD to the unzipped googletest directory
Call configure with sh (part of MSys): sh configure
Call make -> libgtest.a should be built. It is placed in your googletest-directory lib/.libs subdirectory
See README of googletest of how to integrate the libgtest.a to your system. Also see googletest primer in the googletest wiki of how to compile. Alternatively specify the library path for gcc -L<googleTestDir>/lib/.libs and add -lgtest to link with your test project executable.
When using ASSERT_DEATH macro to check for asserts in your tested code (meaning asserts in your lib or application, not in googletest), call SetErrorMode - example main:
#include <windows.h>
#include "gtest/gtest.h"
int main (int argc, char** argv)
{
// this prevents annoying error message boxes popping up
// when assert is called in your program code
SetErrorMode(SEM_NOGPFAULTERRORBOX);
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
You don't need to copy the binaries as long as you have them in your path. Install python and CMake. Test them in your msys (MinGW console)
which cmake
which python
If you see the path, then you have the binaries. If not, add their path to your Environmental Variables>PATH or just update within msys (update installation paths if necessary)
export PATH=$PATH:/c/Program Files (x86)/CMake/bin/cmake.exe:/c/Python27/python.exe
Then you can build as suggested:
cd xxx/gtest-x.x.x
cmake -G "MSYS Makefiles"
make
Test if everything works:
cd make
make
./sample1_unittest.exe
With MSYS2, simply install the mingw-w64-x86_64-gtest package:
pacman -S mingw-w64-x86_64-gtest
Then compile tests with the flags -lgtest -lgtest_main.