Cannot build C++ libraries in MinGW

Pages: 12
Greetings,

I have a problem building a library from sourceforge for use in a C++ program. I am trying to use MinGW32-make on a Win 7 machine.

The library has several components, but for example looking at this one:
http://sourceforge.net/p/libosmscout/code/ci/master/tree/libosmscout/

I have tried searching online and my best bet was to (after navigating to the right directory in command prompt) enter this command:

>>mingw32-make autogen.sh && configure.ac && make

The response I get is:

1
2
3
mingw32-make: Nothing to be done for 'autogen.sh'.
'make' is not recognized as an internal or external command,
operable program or batch file.


Can someone please give me some tips on how to build these libraries?
Thank you,
T
Hi,
When you download raw source tree like in your example "libosmscout" there will be no configure script which is needed for configuration, but you'll find autogen.sh script..

autogen.sh file is used to expand configure script.

once you generate configure script with autogen you then execute configure script to configure.

Once configure script is done configuring you then run make followed by make install.

In order for all these tasks to be successful on Windows the very first thing you need to ensure is to have latest tools such as GNU autotools, compilers and utilities...

Here is how to obtain the latest GNU tools for windows:
Visit below page and follow install instructions:

https://msys2.github.io/

once you do this open the shell (either x32 bit or x64bit depending on your build type) located in MSYS2 installation directory and run following command (copy and paste into console and hit enter)

pacman -S make autoconf autogen automake intltool wget tar itstool bison pkg-config


At this point you can chose which compiler to use with MSYS2 as follows:

To use x64 bit Microsoft compiler and compile the code for Visual Studio, open x64 Visual Studio command prompt and run: (update paths as needed, depending on where you installed MSYS2)

1
2
cd path\to\MSYS2\dir
mingw64_shell.bat


To use Microsoft x86 compiler open x86 command prompt and run:

1
2
cd path\to\MSYS2\dir
mingw32_shell.bat


to use x86 GCC compiler and compile the code for GCC compiler run following from the MSYS2 shell:

pacman -S mingw-w64-i686-gcc

to use x64 bit GCC compiler run this:

pacman -S mingw-w64-x86_64-gcc


Now when you have all the tools you need open MSYS2 shell (again depending on your build type either mingw32_shell.bat or mingw64_shell.bat and cd into sources root directory and run:

NOTE, to use GCC just open one of the *.bat files, to use MSVC run one of the *.bat files from Visual Studio command prompt.

to compile with gcc run:
1
2
3
4
5
cd path/to/libosmscout/
./autogen.sh
./configure CC='gcc' CXX='g++'
make
make install


to configure and compile with MSVC run:
1
2
3
4
5
cd path/to/libosmscout/
./autogen.sh
./configure CC='cl' CXX='cl' LD=link AR=lib CPP='cl -nologo -EP' CXXCPP='cl -E'
make
make install


If there are any errors let us know, you might need to pass arguments to autogen.sh and configure scripts, but try to run as shown above first and see how it goes.

to learn which additional options you can pass to configure script run:
./configure --help

edit:
it is also possible to generate Visual Studio solution without using command prompts:
You do so by installing CMAKE https://cmake.org/

1. run cmake-gui from Visual Studio command prompt, and give input on where you download the sources, also give input on where to build.

2. click on configure button in cmake GUI (select Visual studio version when asked)

3. select generator and hit generate to generate VS solution

4. open solution and build.
Last edited on
Hi,
thanks a lot for the detailed explanation codekiddy. Can you break down this command for me please?
 
pacman -S make autoconf autogen automake intltool wget tar itstool bison pkg-config


The procedure seems to fail at ./autogen.sh step, the output I get is this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
$ ./autogen.sh
configure.ac:148: warning: The macro `AC_TRY_RUN' is obsolete.
configure.ac:148: You should run autoupdate.
../../lib/autoconf/general.m4:2764: AC_TRY_RUN is expanded from...
../../lib/m4sugar/m4sh.m4:639: AS_IF is expanded from...
../../lib/autoconf/general.m4:2031: AC_CACHE_VAL is expanded from...
m4/ax_ext.m4:48: AX_EXT is expanded from...
../../lib/m4sugar/m4sh.m4:639: AS_IF is expanded from...
configure.ac:148: the top level
configure.ac:148: warning: The macro `AC_TRY_RUN' is obsolete.
configure.ac:148: You should run autoupdate.
../../lib/autoconf/general.m4:2764: AC_TRY_RUN is expanded from...
../../lib/m4sugar/m4sh.m4:639: AS_IF is expanded from...
../../lib/autoconf/general.m4:2031: AC_CACHE_VAL is expanded from...
m4/ax_ext.m4:48: AX_EXT is expanded from...
../../lib/m4sugar/m4sh.m4:639: AS_IF is expanded from...
configure.ac:148: the top level
src/Makefile.am:7: error: Libtool library used but 'LIBTOOL' is undefined
src/Makefile.am:7:   The usual way to define 'LIBTOOL' is to add 'LT_INIT'
src/Makefile.am:7:   to 'configure.ac' and run 'aclocal' and 'autoconf' again.
src/Makefile.am:7:   If 'LT_INIT' is in 'configure.ac', make sure
src/Makefile.am:7:   its definition is in aclocal's search path.
autoreconf: automake failed with exit status: 1 


I see that final lines explain the error and suggest how to correct it. But as this is my first time going through this I am quite unsure of what to do =/
You can ignore these errors for now, to fix the problem run following commands one by one:

1
2
3
autoupdate
./autogen.sh
./configure


then post results.

BTW, do you must use gcc? there is a complete VS solution in the source tree.

the command:
pacman -S make autoconf autogen automake intltool wget tar itstool bison pkg-config

installs tools which you need.
Last edited on
Thank you for quick replies.

./autogen.sh appears to give same result as before. Then I get this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
$ ./configure
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for a thread-safe mkdir -p... /usr/bin/mkdir -p
checking for gawk... gawk
checking whether make sets $(MAKE)... yes
checking whether make supports nested variables... yes
checking whether make supports nested variables... (cached) yes
checking for g++... g++
checking whether the C++ compiler works... yes
checking for C++ compiler default output file name... a.exe
checking for suffix of executables... .exe
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C++ compiler... yes
checking whether g++ accepts -g... yes
checking for style of include used by make... GNU
checking dependency style of g++... gcc3
./configure: line 3917: syntax error near unexpected token `win32-dll'
./configure: line 3917: `LT_INIT(win32-dll)'


By the way, what was autoupdate supposed to do exactly?
Forgot to answer you... I am using CodeBlocks IDE with MinGW GCC.
Last edited on
dude, this won't be easy you know without installing all the stuff you need, why not using provided VS solution or CMAKE (see edit in my first post for updates) ?

BTW, have you read their wiki? there is a list of stuff you need to compile this which ever method you use.
http://wiki.openstreetmap.org/wiki/Libosmscout

you can use pacman from MSYS2 to install all needed stuff if you really must compile with gcc

for example:
pacman -Ss "packagename" to list availability of a package

hint: use short name not full name with -Ss:

for example:
pacman -Ss qt

then:
pacman -S "full package name" to download and install.


hey, I've downloaded the sources and it compiles just fine with, a few small fixes are needed. are u still there?
I am still here yes, trying to absorb your explanations in messages. I am new to building 3rd party libraries and this one surely doesn't look like one to start learning with =) But I need to use this library in an application. How did you make it work?
run following:
1
2
3
4
cd /path/to/libosmscout
pacman -S libtool
./autogen.sh
./configure


once configure is done, go to libosmscout/src and make sure there are following files:
1
2
3
Makefile.in
Makefile
Makefile.am


if they are not there then open configure script and use CTRL+F to find LT_INIT(win32-dll)
delete LT_INIT(win32-dll) and run configure only:

1
2
cd /path/to/libosmscout
./configure


and then:
make

post results when done.
Last edited on
So the warning in my very first attempt was relevant after all?
The three Makefile files were present after /.configure

It worked fine until make command, there's a problem:
Makefile:292: *** missing separator. Stop.

Looks like there is problem with "Program files (x86)" part of the path name with spaces

I searched online, putting \t at beginning of line didn't help
Last edited on
directory where libosmscout source code is must not contain spaces, as well as MSYS2 installation must not be installed into location that contains spaces.

for example following installation paths will not work:

1
2
C:\Program Files (x86)\libosmscout\
C:\Program Files (x86)\msys2\



both MSYS2 and source code must be somewhere like following (example):

1
2
C:\msys2\
C:\libosmscout\


also make sure when (and if) you deleted LT_INIT(win32-dll) you deleted only this entry and not more than this.
Ah, the problem is much nastier. libosmscout path does not have any spaces. But Makefile line that caused the mentioned error is path to:
1
2
3
c:/program
files
(x86)/codeblocks/mingw/mingw32/bin/ld.exe


MSYS2 installation is in
C:\msys64

Should I uninstall CodeBlocks IDE and reinstall without compiler coupled with it?
No need to uninstall anything, Please check you PATH variable in control panel under:

Control Panel\All Control Panel Items\System > Advanced system settings> advanced > Environment variables > System variables > Path

make sure there are not mingw or code::blocks paths inside.
you might want to make a backup of a PATH first and then remove mingw and code::blocks stuff from PATH

to check PATH contains only stuff you want in MSYS2 you run:
echo $PATH

You can also uninstall code::blocks completely if you wish. and then later reinstall.

you might also want to 're-configure' sources, by running:
make clean

or remove sources as well, and re-clone them to be 100% sure.

edit:
Should I uninstall CodeBlocks IDE and reinstall without compiler coupled with it?

yes, because there might be problems later when using the library, because you compile library with one GCC version but Code::Blocks uses another version (bundled one)

Only one compiler version should be used, I recommend you to use the one provided with MSYS2.
Last edited on
I removed CodeBlocks path, but I suppose I need to repeat steps from your earlier post so the correct Makefile is produced, right?

I edited PATH for System variables, but echo $PATH apparently returns User variables, which still include CodeBlocks. Also, I need to add C:\msys64\mingw64\x86_64-w64-mingw32\bin to PATH, right? Since now there is no MinGW there.
Last edited on
clear both user and system variables related to code::blocks and mingw, in control panel.
make sure to delete only those related to mingw and code::blocks installation.

nothing needs to be added to path. MSYS2 PATH has nothing to do with Windows PATH, it only inherits the PATH from Windows and that's the problem here.

yes, you need to repeat the steps to generate new make files.
Last edited on
No good =/ that's what I get:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
$ ./autogen.sh
configure.ac:145: warning: The macro `AC_TRY_RUN' is obsolete.
configure.ac:145: You should run autoupdate.
../../lib/autoconf/general.m4:2764: AC_TRY_RUN is expanded from...
../../lib/m4sugar/m4sh.m4:639: AS_IF is expanded from...
../../lib/autoconf/general.m4:2031: AC_CACHE_VAL is expanded from...
m4/ax_ext.m4:48: AX_EXT is expanded from...
../../lib/m4sugar/m4sh.m4:639: AS_IF is expanded from...
configure.ac:145: the top level
libtoolize: putting auxiliary files in '.'.
libtoolize: copying file './ltmain.sh'
libtoolize: putting macros in AC_CONFIG_MACRO_DIRS, 'm4'.
libtoolize: copying file 'm4/libtool.m4'
libtoolize: copying file 'm4/ltoptions.m4'
libtoolize: copying file 'm4/ltsugar.m4'
libtoolize: copying file 'm4/ltversion.m4'
libtoolize: copying file 'm4/lt~obsolete.m4'
configure.ac:145: warning: The macro `AC_TRY_RUN' is obsolete.
configure.ac:145: You should run autoupdate.
../../lib/autoconf/general.m4:2764: AC_TRY_RUN is expanded from...
../../lib/m4sugar/m4sh.m4:639: AS_IF is expanded from...
../../lib/autoconf/general.m4:2031: AC_CACHE_VAL is expanded from...
m4/ax_ext.m4:48: AX_EXT is expanded from...
../../lib/m4sugar/m4sh.m4:639: AS_IF is expanded from...
configure.ac:145: the top level
configure.ac:16: installing './compile'
configure.ac:5: installing './missing'
src/Makefile.am: installing './depcomp'


And then:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
$ ./configure
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for a thread-safe mkdir -p... /usr/bin/mkdir -p
checking for gawk... gawk
checking whether make sets $(MAKE)... yes
checking whether make supports nested variables... yes
checking whether make supports nested variables... (cached) yes
checking for g++... no
checking for c++... no
checking for gpp... no
checking for aCC... no
checking for CC... no
checking for cxx... no
checking for cc++... no
checking for cl.exe... no
checking for FCC... no
checking for KCC... no
checking for RCC... no
checking for xlC_r... no
checking for xlC... no
checking whether the C++ compiler works... no
configure: error: in '.../libosmscout/libosmscout':
configure: error: C++ compiler cannot create executables
See `config.log' for more details 


It seems there is some compiler (path?) setting that I need to make and is missing.
hm, did you restart the MSYS2 shell after changing PATH in Windows?

restart the shell and run:
which g++
it should show you the path to MSYS2 version of g++ compiler

if nothing is shown after restart or there is an error reinstall compiler in MSYS2:
pacman -S mingw-w64-x86_64-gcc

then again:
which g++

run configure only, again.

additionally run:
echo $PATH

and paste output here.
I did restart because echo $PATH still showed unaltered one.

which g++ says no g++ in (/mingw32/bin:/usr/local/bin:/usr/bin:/bin:/c/ProgramData/Oracle/Java/javapath:/c/Program Files (x86)/Java/jdk1.8.0_51/jre/bin/server:/c/Program Files (x86)/Skype/Phone:/c/CooCox/CoIDE/gcc/bin:/usr/bin/site_perl:/usr/bin/vendor_perl:/usr/bin/core_perl)
same after reinstalling compiler with command you provided (I installed 64 bit MSYS2 but was going to use 32bit compiler).

I don't know though what mingw32 in the beggining is doing there. In system settings (env. variables) there is none and also no "perl."
Last edited on
pacman -S mingw-w64-x86_64-gcc installs x64 bit compiler, to use this compiler you need to open mingw64_shell.bat

to use x86 bit compiler you install pacman -S mingw-w64-i686-gcc and then open mingw32_shell.bat.

using x64 bit compiler in "32 bit shell" and vice versa is not possible because PATH's are not the same.

please open mingw32_shell.bat and install 32 bit compiler:
pacman -S mingw-w64-i686-gcc

then run again:
which g++
I suppose I was clusmy here, sorry about that.

now it's:
/mingw32/bin/g++
Pages: 12