Cross-Compiling wxWidgets code from Linux to Windows - c++

I use Code::Blocks IDE with wxWidgets in Debian 8.9 Jessie (x86-64).
When I use the GNU GCC Compiler everything works fine thus compiling nice wxWidgets executable for Linux.
But I need to have my program working on Windows platforms so I have to do cross-compiling.
I have installed mingw32 and followed the cross-compiling instructions given
here.
I did my wxWidgets build configuration as follows:
./configure prefix=/usr/i686-w64-mingw32 --host=i686-w64-mingw32 --enable-unicode --build=`./config.guess` --disable-shared
This is so because the MinGW compiler I have is i686-w64-mingw32, located in the folder /usr/i686-w64-mingw32, and wxWidgets version is 3.1.
My compiler set-up in Code::Blocks should be correct because I managed to do cross-compiling for simple console applications and those run properly on Windows 10.0. But when it comes to wxWidgets applications there are several problems:
The compiler gives me the error (it happens when --static is added to Other compiler options in the build options for the project):
fatal error: wx/app.h: No such file or directory|
Now since wx directory in question is in the path /usr/i686-w64-mingw32/include/wx-3.1 I added this path to the search directories for the project (the build target only for the moment). This worked fine to proceed further.
My compiler settings are: wx-config --host=i686-w64-mingw32 --static --cflags
The compiler swears again (not surprised though :-)):
fatal error: wx/setup.h: No such file or directory|
Ok I've found this one in /usr/i686-w64-mingw32/lib/wx/include/i686-w64-mingw32-msw-unicode-static-3.1, so added this path to the compiler search directories.
The linker is swearing this time (creeping on my nerves):
for the build target:
undefined reference to `wxEntry(HINSTANCE__*, HINSTANCE__*, char*, int)'|
for the release target:
undefined reference to `wxAppConsoleBase::CheckBuildOptions(char const*, char const*)'|
My linker settings are wx-config --host=i686-w64-mingw32 --static --libs
I tried hard to fix this with several different build options for the wxWidgets library but with no effect on the result. So please, someone help!
I also noticed that running ./config.guess form the wxWidgets download directory gives me x86_64-unknown-linux-gnu. Thus this mean I should use x86_64-w64-mingw32 (I have this one installed in /usr/x86_64-w64-mingw32) compiler instead i686-w64-mingw32?

So the main issue is that the command wx-config --static --cflags is not recognized in Other compiler options and wx-config --static --libs is not recognized in Other linker options.
The problem persisted even though I added the path to wx-config file in the .bashrc file from the home directory, i.e. export PATH="$PATH:/usr/i686-w64-mingw32/bin". At that time I was able to run wx-config from the terminal at any location.
To solve it I've changed the options to /usr/i686-w64-mingw32/bin/wx-config --static --cflags in Other compiler options and /usr/i686-w64-mingw32/bin/wx-config --static --libs in Other linker options. This worked as a charm.
I've added the location of libstdc++-6.dll (simply found it with a search in the file manager) in Link libraries and the flags -static and -static-libgcc in Other linker options and finally did the testing with the minimal sample as Igor suggested. Just create new console application, add minimal.cpp file to it and all of the mentioned above.
The compiler did a Minimal.exe file that I have opened successfully with wine.
Note: All the include directories I mentioned in my question were in wx-config --cflags for the compiler and wx-config --libs for the linker, so no need to add them in search directories.

Related

Link PCL libraries while compiling C++ programs in Linux

I am new to the Point Cloud Library. There is a thing that has been bugging me for some time.
So, on my system, whenever I have to compile a C++ program, which requires OpenCV libraries to be linked, I use the following terminal command:
g++ -std=c++11 fileName.cpp -o executableFile `pkg-config --cflags --libs opencv`
Now, things have turned to a point where I have to use PCL. But, everywhere (including the PCL's official website) people link PCL libraries using a CMake file, and I am not familiar with CMake.
Is there a way to include the PCL libraries without writing a CMake file and just including some more flags/parameters to the terminal command?
I am using Ubuntu 18.04.
I experimented for a while, and here is how I figured this out.
man pkg-config tells you the folders where pkg-config looks for .pc files. So, I checked those folders for the exact .pc file names that I want pkg-config to link with my .cpp file. I found the required file (pcl_io-1.11.pc) at \usr\local\lib\pkgconfig
Next, I modified my terminal command to the following (please consider two back-quotes as a single back-quote below)
g++ -std=c++14 pcd_write.cpp -o pcd_write ``pkg-config --cflags --libs pcl_io-1.11`` -lboost_system
Note: Not including the -lboost_system would result in another error message. I found this helpful.
This compiled successfully. But, on running the executable, I would get this error message:
./pcd_write:error while loading shared libraries:libpcl_io.so.1.11:cannot open shared object file:No such file or directory
The solution to this problem was found here
sudo /sbin/ldconfig -v
Then, running the executable gave the expected results.

How to link statically to wxWidgets from Kdevelop on linux?

Hello I have installed wxWidget-3.1.0 s on windows it works fine using it from MSVC++. But On Linux fedora 27 I built it in a sub-directory "wxWidget3.1.0/build-gtk-unicode-release".
These are the comands:
../configure --disable-debug
make
sudo make install
sudo ldconfig
Above it generates for me a release shared library I get around building programs upon it. So I easily use "wx-config --cxxflags --libs". For Ides like Eclipse, Codeblocks, Kdevelop.
The problem is I need some "static version" of the library so I created another sub-directory: "wxWidgets-3.1.0/build-gtk-static-release-unicode" So I issued the commands:
../configure --disable-debug --disable-shared --enable-unicode
make
sudo make install
I created a project with Codeblocks and it compiles easily with adding only "wx-config --cxxflags --libs"
When it comes to Eclipse CDT I used wx-config --cxxflags for the compiler and wx-config --libs for the linker. But it fails complaining
about "Unreferenced defeinition of the APIs".
After a long search I Find a tricky workaround:
Project->Properties->C/C++->GCC C++ Linker->Experts settings:
${COMMAND} ${FLAGS} ${OUTPUT_FLAG} ${OUTPUT_PREFIX}${OUTPUT} ${INPUTS}
So I made the "Flags" at the end to become:
${COMMAND} ${OUTPUT_FLAG} ${OUTPUT_PREFIX}${OUTPUT} ${INPUTS} ${FLAGS}
And it works fine.
*** The problem:
I'd like to configure Kdevelop for wxWidgets as a static library keep in mind as a dynamic library I managed to do that. So My Configurations are:
From Kdevelop->Project->Open Configuration->CMake File->CXX_COMPILER_FLAGS I enters:
The result of wx-config --cxxflags in a terminal.
And for the linker:
CXX_LNKER_FLAGS:
The reult of wx-config --libs
But The code compiles but doesn't build I don't have "expert settings" as in Eclipse CDT.
Can anyone solve how to link to wxWidgets from Kdevelop statically?
Thank you for this boring long story. NB: I Added What problems I faced and what did to get around them to help people who face the same problems. Thank you in advance.

Using CodeLite IDE for OpenCV in Ubuntu 16.04 LTS

I can compile a sample C++ Code (including OpenCV) using both CMake and following command line:
g++ cv.cpp -o cvapp pkg-config --cflags --libs opencv
But I want to use CodeLite IDE for this purpose. I have added
/usr/include/opencv;/usr/include/opencv2
in the Include Paths under compiler tab in project settings. And added
/usr/local/lib
in Libraries Search Path under Linker tab.
But still, I am getting errors shown in this screenshot for a sample code.
Now is it possible to use CodeLite for OpenCV coding environment? If yes then how?
To use opencv in codelite the simplest option is to continue using pkg-config, you can do this as follows:
Right click on the project name and select settings...
2.Open the following dialog and select the Linker tab, in that window add pkg-config --cflags --libs opencv in linker-options:
Press the apply button and Ok and then compile the project.

Missing "libiconv.h" when crosscompiling for Windows with mingw on Ubuntu

I have been working on a program in SDL and I would like to send it to my friends who only run a Windows environment. I have done some reading and found that I should use mingw to cross-compile for Windows. The binary I found and compiled was x86_64-w64-mingw32-g++, however I am getting some issues getting my program to compile. Using the following command I get the following error:
/usr/bin/x86_64-w64-mingw32-g++ sapphire.cpp `pkg-config --cflags --libs sdl2` -lSDL2_image -lSDL2_mixer -lSDL2_ttf -std=c++11
fatal error: iconv.h: No such file or directory
While I realize I should make a makefile eventually, I am not going to do that now.
I tried installing iconv (Version 1.15) from here and used the following commands to compile it:
./configure --prefix=/usr/local
make
make all
My iconv.h is located in /usr/include but if I include that I get another error for missing gnu/stubs.h and if I include that then I get a myriad of errors that I'm not sure how/if I could fix seen here. Does anyone know how I could perhaps fix this? I would appreciate any help!
Thanks in advance!
You can use pkg-config with mingw in a crosscompiler environment but you should take care to where pkg-config searches for his .pc files.
I'm assuming your mingw crosscompiler is installed in /usr/x86_64-w64-mingw32, change it to the installation path where his "include" and "lib" subdirectories are.
Provided SDL windows developement package is installed in the same prefix on your computer and the installation has a correct pkg-config .pc file you can do:
export PKG_CONFIG_PATH=/usr/x86_64-w64-mingw32/lib/pkgconfig
and then try pkg-config from the command line:
pkg-config sdl2 --cflags
This should point you to some path inside /usr/x86_64-w64-mingw32, if it does your compilation will be successful.
Please note that if you want to compile a package for crosscompile (like the iconv you tried to compile) you should add to the ./configure script parameters:
--host=x86_64-w64-mingw32 --prefix=/usr/xx86_64-w64-mingw32
... and this may work or not, depending the package support the mingw32 compiler or not.
The way you compiled iconv built another linux version of it in /usr/local!
NOTE: As far as I know Ubuntu does not provide a windows package for SDL2, while other linux distro do, so you'll need to cross-compile SDL2 with the option I gave before you can compile your code. SDL2 does support cross-compilation using mingw.

Linking the Allegro library to a C++ application using the g++ compiler (Ubuntu)

In trying to get Allegro (A C++ game programming library) to work with a very simple C++ application in Ubuntu 12.04, I am unable to get the program to compile with the allegro header definitions. It returns the error allegro.h - no such file or directory found. I tried running a pkg-config to find the proper linker command, but that didn't help in compilation.
I am almost certain it is installed correctly at this point. I tried using a pkg-config --cflags --libs allegro-5.0 for the include file paths, none of which worked when using in the g++ compile line.
Thanks in advance.
Running a pkg-config --cflags --libs allegro-5.0 told me wrong on the include path. It told me to use -I/usr/local/include and after some digging into that folder, I found that the include path is -I/usr/local/include/allegro5 instead. It is compiling fine now.