Integrating wxWidgets into Existing XCode Project - c++

There are many tutorials about setting up a new XCode project for use with wxWidgets, but I need to integrate it with a large existing XCode C++ project.
The wxWidgets setup process is unclear to me. I built wxWidgets in XCode with the included wxcocoa.xcodeproj file. But when I include all the header files and the libwx_osx_cocoa.dylib library to my existing XCode project, I get all these errors within the wxWidgets header files like Use of undeclared identifier 'wxApp' and No matching constructor for initialization of 'wxEvent' as if it's missing files, but I've included all the header files and compiled library. I tried building wxWidgets in the terminal and get the same errors. I tried make install to actually install wxWidgets on my system. I tried running this command wx-config --cxxflags --libs all in the terminal. I tried adding wx-config --cxxflags and wx-config --libs all to the compiler and linker flags in my XCode project. None of these had any effect.
The irony is that I'm trying to use wxWidgets library to make the GUI process easier, but instead I've spent two days pulling my hair out trying to get my C++ XCode project to compile. Does anyone know what I'm doing wrong?
EDIT: The problem seems to be XCode. I've downloaded the wxWidgets Hello World sample program at the bottom of this page. I can build this program without issue in the terminal, but when I put it into a new XCode project, it won't build. How can I get XCode to build this simple program?
cx-config output:
XCode project settings:
EDIT 2: I exported the Build Log out of XCode and saw that the actual build command uses clang. When I successfully compile Hello World in the terminal, I use clang++. When I try the same command with clang, it doesn't work. Perhaps this is the issue, since clang only links C libraries and the errors XCode is giving me relate to not being able to find standard C++ functions.
EDIT 3: Wow I hate XCode. I got my Hello World program to compile by accident. The solution was putting the wxWidgets compiler flags in the Targets Build Settings, whereas before, I had it in the Project Build Settings. I assumed the Targets would inherit the Project settings, but I guess not!
EDIT 4: I got my complicated XCode project to compile with the wxWidgets libraries by taking all the search paths & flags and moving them from the Project Build Settings to the Targets Build Settings. What a nightmare! Glad it's over

#WaddleDee72
,
I suggest doing following:
Delete wxWidgets directory.
Unpack wxWidgets into i.e. ~/wxWidgets.
Open Terminal.
In the Terminal
4a. cd ~/wxWidgets
4b. mkdir buildOSX
4c. cd buildOSX
4d. ../configure --enable-debug
4e. make -j5
After successful build
wx-config --cxxflags
wx-config --libs
Use the output of 2 commands above and put the values where they belong in XCode project.
If you get any issues - let us know.
Thank you.

Related

How to compile Quantlib via Xcode?

I am trying to install QuantLib on my Mac running OSX 10.11.6. Installed Boost 1.59 via MacPorts and then followed these instructions.
I used these additional environment variables
./configure --with-boost-include=/opt/local/include/ \
--with-boost-lib=/opt/local/lib/ --prefix=/opt/local/ \
CXXFLAGS='-O2 -stdlib=libstdc++ -mmacosx-version-min=10.6' \
LDFLAGS='-stdlib=libstdc++ -mmacosx-version-min=10.6'
and then make && sudo make install.
However when I run the Bermuda Swaption test it gave me the same error described here.
Little premise: I don't know anything about C++. I need QuantLib to work on Python. So I read carefully the answer by SmallChess and tried to solve it by myself. As I read in his answer
You can't just compile BermudanSwaption.cpp and hope everything would be fine. You have to compile the entire QuantLib library and link with the generated library files. Please google "compiling and linking C++" for more information.
By far, the easiest way to make it happen on Mac is to do it with Xcode. You will need to create a new Xcode project, and import the entire Quantlib project files into it. Next, you will need to create a main() function. Xcode does the compiling and linking for your automatically.
This is what I exactly did:
created a new project in Xcode (version 8.2.1)(file/new project/Command Line Tool/"HelloWorld"/Documents/create)
selected Targets, Build Phases and Link Binary With Library. Added libQuantLib.0.dylib
set libstdc++(GNUC++ standard library) as C++ Standard Library in Build Settings
Modified Header Search Paths to include: /opt/local/include/, and Library Search Paths to include: /opt/local/lib
C++ Language Dialect is set on Compiler Default.
Dragged the ql folder onto the left window of the Xcode
Now, I managed to copy a simple code which includes the library and even if there are many warnings, it runs. Still when I run on the Terminal the command for the Bermuda Swaption test I get the same error. What am I doing wrong?
Additional info (may or may not be useful): if I change the C++ Standard Library setting on Xcode to libc++, I get on Xcode the same error I get when i try the Bermuda Swaption test (ld: symbol(s) not found for architecture x86_64).
Any help would be very much appreciated
Regards
EDIT: you can find a picture of the code at https://i.stack.imgur.com/1zhjO.png

How to build Crypto++ library on Linux with MinGW?

im trying to port a c++ project from visual studio 2013 to netbeans on ubuntu. The target is a windows executable, so far im able to compile windows exe files from netbeans using mingw as compiler.
The project needs the Crypto++ library and i only have the .lib version for visual studio. To include the library in netbeans i first need to build the Crypto++ library in the .a format.
Its not clear to me how should i do that.
Ive found informations on how to build the library for linux with mingw but not for cross compilation with mingw. The provided GNUmakefile does not work.
Should i set up a vm with windows and mingw and compile the library that way? Or maybe use the qmake "hack" as suggested here http://www.qtcentre.org/threads/28809-Compiling-amp-using-Crypto-with-mingw-version-of-Qt ? The last good Crypto++ version suggested there is quite old. This is confusing, porting the whole project is easier than having the required library.
Im open to any suggestion.
tldr: how to build libcryptopp.a on linux for the cross compilation of a windows exe project
edit:
for example if i cross compile something there are windows libraries in the /usr/i686-w64-mingw32/lib/ folder like libuser32.a. i need to make the equivalend libcryptopp.a.. sorry if is a bit unclear.
if i simply build using the steps in answer (and in the wiki) i end up with a libcryptopp.a file but i suspect is linux-only, cause if i link that library in netbeans in the .exe file im cross compiling i end up with undefined references to cryptopp stuff everywere. the paths are correct, i suspect the library needs to be replaced with the equivalent libcryptopp.a compatible with crosscompiling.
edit2: im trying to follow the answer down here, now im stuck here. after this command to build cryptopp.
make CXX=/usr/bin/i686-w64-mingw32-gcc INCLUDES="-I /usr/i686-w64-mingw32/include" LIBS="-L /usr/i686-w64-mingw32/lib" CXXFLAGS="-std=c++0x"
and many variations of it i always end up with this error
trap.h:26:25: fatal error: Windows.h: No such file or directory
# include
which makes me think its using the right compiler to make a .a lib file for cross compiling the windows .exe with the lib.
however i dont understand whats going on now with the missing header..:(
Also if i try to link the lib file (used with visual studio) i get a lot of linking errors, undefined reference to cryptopp stuff.
ill offer a symbolic beer (a couple of $ of Bitcoins) if someone finds out how to do it.
Inspired by http://wiki.amule.org/wiki/Cross-compilation_for_windows_with_mingw:
sudo apt-get install mingw-w64
git clone https://github.com/weidai11/cryptopp
cd cryptopp
export TARGET=i686-w64-mingw32
CXX=$TARGET-g++ RANLIB=$TARGET-ranlib AR=$TARGET-ar LDLIBS=-lws2_32 make -f GNUmakefile
I've found informations on how to build the library for linux with mingw but not for cross compilation with mingw.
Its relatively easy...
Get Crypto++ ZIP into MinGW.
Unpack Crypto++ ZIP.
Change directories.
Build the library.
Verify All tests passed.
(1) and (2) can be tricky because Cygwin and MinGW are missing a lot of tools. So curl https://www.cryptopp.com/cryptopp563.zip -o cryptopp563.zip may not work.
For (2), I seem to recall ZIP is missing, so unzip -aoq cryptopp563.zip -d cryptopp-5.6.3 may not work.
At step (4), just perform make static dynamic test and be sure it finished with All tests passed.
I do a lot of testing with Cygwin and MinGW. I have a script that copies Crypto++ into the environments from my Desktop. I have not been able to figure out a way to automate it. A recent question on automating it was closed, so no one can supply an answer (see How to automate software testing for Cygwin and MinGW).

Xcode 4.2 create xcode sample project

I have a task to create xcode4 project. The project will be used by other people to open with xcode4, build it and run. The problem is that we use wxWidgets library and by creating xcode project I have to make sure that it has valid wxWidget library path set.
To get valid wxWidgets lib path using terminal is simple:
wx-config --cxxflags
wx-config --libs
How to configure xcode to call these commands and use it's output to set library path?
Use CMake. You write text script and it generates XCode project on other developer's machine using this script and puts correct local paths into XCode project or Makefile.
To the best of my knowledge you can't configure Xcode to run anything so you need to copy and paste the output of these commands into compiler/linker options manually.

How to install protobuf on windows? (Win7x64/MinGW)

C++-Protobuf does not compile in VS2012. Now I want to use MinGW to compile it on windows. Can someone please give me some brief headwords on how to compile protobuf on Win7 x64. I already installed MinGW with the GUI installer. Google writes as MinGW setup notice that I should refer to the Unix installation notes. But I cant figure out how to use the auto tools on windows.
Edit
Okay this is what I've done until now:
$ mount C:/ WinDir
$ cd ./[...]/protobuf.2.4.1
$ ./configure
$ minGW32-make.exe
$ minGW32-make.exe check
minGW32-make.exe runs without errors, but no tests are running and I cant find libprotobuf.lib. There are some libprotobuf.dll but I need the lib, dont I?.
You should have an MSys console together with your MinGW instalation. This console provides an linux-like environment in which you should be able to use autotools normally.
If MSys is not installed, you can grab it from the MinGW site too.
cd to your directory with sources and try the usual:
$ ./configure
$ make
Some libraries cause problems on Windows but most compile well with MinGW and MSys. Come back and add more info to your question if you run into specific problems.
Edit:
minGW32-make.exe runs without errors, but no tests are running and I cant find libprotobuf.lib. There are some libprotobuf.dll but I need the lib, dont I?.
Usually for a dynamic library you'd get protobuf.dll (the dynamic library) and libprotobuf.a (the static wrapper library).
When linking, just pass -lprotobuf to the linker - it will look for both libprotobuf.a and protobuf.lib.
(.lib is another static library format, which is partially handled by MinGW but not native here.)
You will not work with a .lib file when using the MinGW toolchain. Instead, you are able to link against the dll directly. The MinGW Wiki explains this.
I could get dll and lib both. This is when you do not want static lib file and want to use dll and lib file.
You need to make following changes in Protobuf code:
Open the project in VS. Or any other editor. I use VS2015.
In libProtoBuf project settings, in C/C++ Preprocessor add following flags.
PROTOBUF_USE_DLLS; LIBPROTOBUF_EXPORTS;
Those flags will export information from profobuf using dllexport
in ur client code where you are using Protobuf, define: PROTOBUF_USE_DLLS. Which will make protobuf includes to use dllimport.
Once you do step 2, you will see both dll and lib in your output folder. Otherwise, you will always see just dll and not lib file.
Hope this helps. If not, please write a message here and I can help you getting this sorted out.

Bullet Physics, CMake->CodeBlocks - MinGW: Doesn't find GL/glut.h?

Statistics...
My System: Windows Vista 64 bit
Library: Bullet Physics v2.78
Makefile Generator: CMake
Build system: MinGW command line, MinGW + CodeBlocks
Makefiles were implemented by command line and through CMake-generated Code::Blocks project
In both cases, the build fails near 30%. NOTE: I did have to switch the build executable in the Code::Blocks project from make.exe to mingw32-make.exe
First Failure: Demos\OpenGL\GLDebugFont.cpp -> GL/glut.h: No such file or directory
Second Failure (after commenting out the #include from the first) -> Demos/OpenGL/GlutStuff.h: same error
These failures happen when I build command-line OR through the generated C::B project.
Why can't it find GL/glut.h? "bullet-2.78\Glut\GL\glut.h" exists. Maybe there's a way I can tell it to find glut there?
NOTE: During the CMake makefile generation, CMake did tell me that "You are using the obsolete GLU package, please use OpenGL instead." It continued as normal with the Makefile generation. Maybe I need to define some environment variables? Maybe I need to configure something in Windows that CMake is looking for?
I would add a compiler search path in bullet-2.78/Glut, but Code::Blocks doesn't allow that if you're using a custom makefile (like a CMake-generated one).
UPDATE: I have been able to build the library itself, by building specific targets in the Code::Blocks project. However, I have been unable to build any of the demos or the benchmark test, since they all use OpenGL (and apparently glut.h). I would still like to compile those.