How to change to use the g++ mingw toolchain under cygwin - c++

It looks like g++/gcc-mingw is installed but I can't tell how to use it.
I am building a C source file with a windows main proc and I get this error:
g++-3 -mwindows -L/usr/lib/gcc/i686-pc-mingw32 -lmingw32 winmain.c
/usr/lib/gcc/i686-pc-cygwin/3.4.4/../../../../i686-pc-cygwin/bin/ld:
cannot find -lmingw32 collect2: ld returned 1 exit status
Or
$ g++-3 -mwindows -L/usr/lib/gcc/i686-pc-mingw32 winmain.c
/tmp/ccyLGxkn.o:winmain.c:(.text+0x21): undefined reference to
`MainWndProc(HWND__*, unsigned int, unsigned int, long)#16' collect2:
ld returned 1 exit status
If I do a list directory on the installed libraries I see this:
$ ls /usr/lib/gcc/ i686-pc-cygwin/ i686-pc-mingw32/
Note: 'i686-pc-mingw32' How do I compile using the mingw32 libraries?
Also, I installed the package: 'gcc-mingw-g++' through the cygwin setup.exe utility, I just don't know how to use it?
Note: I am mostly working with 'cygwin', I would prefer NOT to install the full ming install?

There are actually two sets of projects, the libraries and the actually toolchain. I installed the libraries and not the toolchain.
The libraries are: gcc-mingw-g++
mingw64-i686-gcc is the toolchain
I ran with this command and it worked correctly:
i686-pc-mingw32-g++
i686-w64-mingw32-g++
Or:
i686-w64-mingw32-g++ -mwindows -static -I/opt/jdk/include
-I/opt/jdk/include/win32 -Wl,--add-stdcall-alias -shared -o Hello.dll Hello.cpp

Related

Building GDAL with all libraries static

I want to develop a small program that checks which polygons from a shapefile intersect a given rectangle. This program is to be used in a website (with PHP's exec() command). The problem is, my webserver cannot install GDAL, for reasons unknown to me. So I can't link to the shared libraries. Instead, I must link to static libraries, but these aren't given.
I've downloaded the GDAL source code from here (2.3.2 Latest Stable Release - September 2018), and followed the build instructions from here. Since I already have GDAL working on my Debian, and don't want to mess with it, I followed the "Install in non-root directory" instructions, with some adjusts from the last item in the "Some caveats" section:
cd /home/rodrigo/Downloads/gdal232/gdal-2.3.2
mkdir build
./configure --prefix=/home/rodrigo/Downloads/gdal232/gdal-2.3.2/build/ --without-ld-shared --disable-shared --enable-static
make
make install
export PATH=/home/rodrigo/Downloads/gdal232/gdal-2.3.2/build/bin:$PATH
export LD_LIBRARY_PATH=/home/rodrigo/Downloads/gdal232/gdal-2.3.2/build/lib:$LD_LIBRARY_PATH
export GDAL_DATA=/home/rodrigo/Downloads/gdal232/gdal-2.3.2/build/share/gdal
/usr/bin/gdalinfo --version
build/bin/gdalinfo --version
The first /usr/bin/gdalinfo --version gives 2.1.2 (the previous installed version). The second, build/bin/gdalinfo --version, gives 2.3.2 (the version just built).
By now, my program only uses the ogrsf_frmts.h header, which is in /usr/include/gdal/ or /home/rodrigo/Downloads/gdal232/gdal-2.3.2/build/include/ directory, depending on the build. There's no ogrsf_frmts.a file, but only a libgdal.a. Is this the file I should be linking against? If so, how? I've tried so far:
gcc geofragc.cpp -l:libgdal.a
gcc geofragc.cpp -Wl,-Bstatic -l:libgdal.a
gcc geofragc.cpp -Wl,-Bstatic -l:/home/rodrigo/Downloads/gdal232/gdal-2.3.2/build/lib/libgdal.a
gcc geofragc.cpp -Wl,-Bstatic -l/home/rodrigo/Downloads/gdal232/gdal-2.3.2/build/lib/libgdal.a
gcc geofragc.cpp /home/rodrigo/Downloads/gdal232/gdal-2.3.2/build/lib/libgdal.a
gcc geofragc.cpp -l/home/rodrigo/Downloads/gdal232/gdal-2.3.2/build/lib/libgdal.a
gcc geofragc.cpp -l:/home/rodrigo/Downloads/gdal232/gdal-2.3.2/build/lib/libgdal.a
but nothing works. What am I missing?
EDIT
The second trial (gcc geofragc.cpp -Wl,-Bstatic -l:libgdal.a) is giving the following error:
/usr/bin/ld: cannot find -lgcc_s
/usr/lib/gcc/x86_64-linux-gnu/6/../../../../lib/libgdal.a(gdalclientserver.o): In function `GDALServerSpawnAsync()':
(.text+0x1f5e): warning: Using 'getaddrinfo' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/usr/bin/ld: cannot find -lgcc_s
collect2: error: ld returned 1 exit status
You can use the gdal-config program to get correct options for compilation and linking. This program is a part of the GDAL library and it has its own options:
hekto#ubuntu:~$ gdal-config --help
Usage: gdal-config [OPTIONS]
Options:
[--prefix[=DIR]]
[--libs]
[--dep-libs]
[--cflags]
[--datadir]
[--version]
[--ogr-enabled]
[--gnm-enabled]
[--formats]
You have to make sure this program is on your search path, or you can create an alias - for example:
alias gdal-config='/home/rodrigo/Downloads/gdal232/gdal-2.3.2/bin/gdal-config'
Now your compilation and linking command becomes the following one:
g++ `gdal-config --cflags` geofragc.cpp `gdal-config --libs` `gdal-config --dep-libs`
You have to use the g++ compiler to link with C++-built libraries.
Another option is to create a Makefile with these lines:
CXXFLAGS += ${shell gdal-config --cflags}
LDLIBS += ${shell gdal-config --libs}
LDLIBS += ${shell gdal-config --dep-libs}
geofragc: geofragc.cpp
and just call make with this Makefile.
I hope, it'll help.

libgtest.so error adding symbols: DSO missing from command line

I have been using gtests for unit testing a personal project. Last week I upgraded to the LTS version of Linux Mint. Unfortunately, after that event, I haven't been able to compile my project due to gtests linking problems.
The following error is being issued:
/usr/bin/x86_64-linux-gnu-ld: build/tests/policies/roundrobin_tests.o: undefined reference to symbol '_ZN7testing4TestC2Ev'
/home/myuser/Documents/googletest-release-1.8.0/googletest/libgtest.so: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
I have generated both libgtest.so and libgtest_main.so through CMake 3.10.2. The gtest version is the release-1.8.0, the same I used to have before.
Those libraries are located in /usr/lib and the corresponding include folder has also been copied to /usr/include. I made sure that this location is in my ld path and that is not the problem.
My compiler is g++ v7.3.0 and the command Im using to compile the testes is:
g++ -std=c++14 -Wall -O3 -Iinclude build/tests/policies/roundrobin_tests.o -lgtest_main -pthread -o bin/policies/roundrobin_tests
I have tried altering the order of the elements in the command, explicitly adding -L/usr/lib and -I/usr/include without luck. A funny fact is that if I take off the -pthread flag, the error is still the same.
The same command was used before and the only difference is the compiler version I am using now as I used g++ 5.4.0 before. Any insights on how to solve this?
edit: Just tested the same process with g++ 5.4.0 and CMake 3.5 and the same problems ocurred.

How can I compile a C++ program with root library includes using g++?

I have written a C++ program (mainPixelDet1.C that uses a class defined in PixelDet1.C), that works in root's interactive mode.
But now I want to compile it outside root, using g++.
Here's what I write on the Terminal:
g++ -o main mainPixelDet1.C PixelDet1.C `root-config --cflags --glibs`
And here's what I get:
/usr/bin/ld: cannot find -lGraf3d
usr/bin/ld: cannot find -lPostscript
/usr/bin/ld: cannot find -lPhysics
collect2: error: ld returned 1 exit status
You'll have to also include --ldflags to root-config, so that root-config will supply the necessary library flag arguments.
I had the same problem and I just solved it installing these libraries: "libroot-*", "root-plugin-*","ttf-root-installer".`
I find the answer on ROOT forum if you interested, here is the link:
https://root.cern.ch/phpBB3/viewtopic.php?t=16352.
To install the library, you can write on terminal the follow command line:
sudo apt-get install nameoflibrary

Boost with eclipse cannot find thread library

I have downloaded and build the boost libraries with
bootstrap mingw
and
b2 toolset=gcc
and the libraries are created in
C:\Boost\boost_1_57_0\stage\lib
In eclipse I have added this directory as a library path
and added the library libboost_thread-mgw49-mt-1_57 with and without the .a on the end.
the g++ line looks like
g++ "-LC:\\Boost\\boost_1_57_0\\stage\\lib" -o MyThread.exe main.o MyThread.o -llibboost_thread-mgw49-mt-1_57
and I get the error message
ld.exe: cannot find -llibboost_thread-mgw49-mt-1_57 collect2.exe: error: ld returned 1 exit status
If I add the .a it is appended to the error message as expected.
what am I doing wrong?
Specify the library without the lib prefix (which is the UNIX convention):
g++ "-LC:\Boost\boost_1_57_0\stage\lib" -pthread -o MyThread.exe main.o MyThread.o -libboost_thread-mgw49-mt-1_57
There's even a chance that (with the help of some standard convention symlinks) you could just say -lboost_thread.
PS Don't forget to use -pthread as well

Program with protocol-buffers don't compile with MinGW-w64: "undefined reference to google::protobuf:: ..."

I have installed the libprotobuf-dev=2.6.0-4 and protobuf-compiler=2.6.0-4 packages from Debian Jessie repository. Now I'm trying to compile a program that use the 'addressbook.proto' file from the Google Developers example with the MinGW-w64 compiler. I'm using Ubuntu 14.04.
With this command the program works:
$ g++ main.cpp addressbook.pb.cc -lprotobuf
But I want to compile for Windows too.
I added the symlink: /usr/include/google -> /usr/i686-w64-mingw32/include/google.
$ i686-w64-mingw32-g++ main.cpp addressbook.pb.cc -lprotobuf
/usr/bin/i686-w64-mingw32-ld: cannot find -lprotobuf
collect2: error: ld returned 1 exit status
With the library location still not working:
$ i686-w64-mingw32-g++ -L /usr/lib/i386-linux-gnu/ main.cpp addressbook.pb.cc -lprotobuf
/tmp/ccB1VJyR.o:main.cpp:(.text$_ZN6google8protobuf8internal27GetEmptyStringAlreadyInitedEv[__ZN6google8protobuf8internal27GetEmptyStringAlreadyInitedEv]+0x7): undefined reference to `google::protobuf::internal::empty_string_'
/tmp/ccB1VJyR.o:main.cpp:(.text$_ZN6google8protobuf8internal27GetEmptyStringAlreadyInitedEv[__ZN6google8protobuf8internal27GetEmptyStringAlreadyInitedEv]+0x2f): undefined reference to `google::protobuf::internal::empty_string_'
/tmp/ccPz4uiI.o:addressbook.pb.cc:(.text+0x78): undefined reference to `google::protobuf::DescriptorPool::generated_pool()'
/tmp/ccPz4uiI.o:addressbook.pb.cc:(.text+0x87): undefined reference to `google::protobuf::DescriptorPool::FindFileByName(std::string const&) const'
...
libprotobuf-dev contains library headers and pre-built binaries for your system. If you are cross-compiling you need to compile library from sources to target system as well. Something like "./configure CC=i686-w64-mingw32-g++" in library sources directory should do the job.