Setup Xcode and FLTK - c++

Errors I get when trying to build the first block of code on this page under Xcode
Undefined symbols for architecture x86_64:
"fl_define_FL_SHADOW_LABEL()", referenced from:
_main in main.o
I installed FLTK with homebrew by brew install FLTK and there were no errors:
/usr/local/Cellar/fltk/1.3.2_1: 315 files, 5.8M, built in 93 seconds
I realize this problem has been asked before, but the answer
You need to install it first as it's not on Mac OS X, using something like homebrew/macports/manually which will provide you with an installed copy that can be referenced using the User Header Search Paths and Library Search Paths, as well as referencing the fltk library(/ies) in the Linked Frameworks and Libraries
did not work for me or I got the specific file paths wrong. I have tried Xcode 5.1.1 and 6.0 and both have the same problem.
I have attached a screenshot of my build settings.

I have found the solution at groups.google.com and below is what I have done:
Change build settings as such:
Header Search Paths : -I/usr/local/include
Library Search Paths : /usr/local/lib
Go to terminal and type fltk-config --ldflags
You get a line of flags, mine was
-L/usr/local/Cellar/fltk/1.3.2_1/lib -lfltk -lpthread -framework Cocoa.
In Xcode Build settings, paste that in other linker flags
After these steps Xcode compiled the file successfully.

Related

Cross-Compiling wxWidgets code from Linux to Windows

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.

Library not found for -ljson11 but -lsqlite 3 is found

I'm trying to implement this tutorial with the addition that I want to include the json11 C++ library.
I followed the same process for both, downloaded the repo from:
https://github.com/libmx3/mx3, added them to the /deps/ folder of my project, and ran GYP to generate the .xcodeproj files for both.
Then I create a C++ project, add both the projects into the workspace, and add the libraries under Build Phases->Link binaries with libraries.
When I hit run the build fails with ld: library not found for -ljson11
I have tried regenerating them and adding them into the main xcodeproj. and into the Target Dependencies.
I have double-checked the library projects and they are identical. I have also added the folders where the .a files are compiled in Library Search paths but none of this makes a difference. If I remove the json11 dependency the project compiles, but I can't understand why the sqlite3 is found and throws no errors but the identical json11 project won't work.
I can see the .a files in the Debug-build folder and there are no errors if I build them separately.
Heres the full build log
Ld /Users/myuser/Library/Developer/Xcode/DerivedData/DjinniTest-eqaqzcfyskdxupbqpdngkdmoidtq/Build/Products/Debug/DjinniTest normal x86_64
cd /Users/myuser/Documents/Dev/djinni_test/cpp_project
export MACOSX_DEPLOYMENT_TARGET=10.11
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++
-arch x86_64
-isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk
-L/Users/myuser/Library/Developer/Xcode/DerivedData/DjinniTest-eqaqzcfyskdxupbqpdngkdmoidtq/Build/Products/Debug
-L/Users/myuser/Library/Developer/Xcode/DerivedData/DjinniTest-eqaqzcfyskdxupbqpdngkdmoidtq/Build/Products/Debug/..
-F/Users/myuser/Library/Developer/Xcode/DerivedData/DjinniTest-eqaqzcfyskdxupbqpdngkdmoidtq/Build/Products/Debug
-filelist /Users/myuser/Library/Developer/Xcode/DerivedData/DjinniTest-eqaqzcfyskdxupbqpdngkdmoidtq/Build/Intermediates/DjinniTest.build/Debug/DjinniTest.build/Objects-normal/x86_64/DjinniTest.LinkFileList
-mmacosx-version-min=10.11
-stdlib=libc++
-ljson11
-lsqlite3
-Xlinker
-dependency_info
-Xlinker /Users/myuser/Library/Developer/Xcode/DerivedData/DjinniTest-eqaqzcfyskdxupbqpdngkdmoidtq/Build/Intermediates/DjinniTest.build/Debug/DjinniTest.build/Objects-normal/x86_64/DjinniTest_dependency_info.dat
-o /Users/myuser/Library/Developer/Xcode/DerivedData/DjinniTest-eqaqzcfyskdxupbqpdngkdmoidtq/Build/Products/Debug/DjinniTest
ld: library not found for
-ljson11
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Edit: even if I add the compiled files into the project so that they turn black, it still complains that the ljson11 library is not found. Maybe there's something wrong with the way the library is compiled?
Both the libraries gave warning that "macosx" was not found in the supported platforms. When I added it into the json11 project settings, the build compiled and both the warnings disappeared.
SQlite3 still only has iOS(iphone,iphonesimulator) but it compiles fine. I wonder what the difference is.

SFML 2.1 Undefined symbols for architecture x86_64 error

I have recently installed SFML 2.1 and am trying to compile and run from the terminal, NOT Xcode, the sample program that they have on their website at http://www.sfml-dev.org/tutorials/2.0/start-linux.php.
Path to where I installed SFML:
/Users/.../Desktop/C++_Code/SMFL/SFML-2.1-osx-gcc-universal
However, I keep getting the error of:
Undefined symbols for architecture x86_64:
"sf::String::String(char const*, std::__1::locale const&)", referenced from:
_main in window-48cb4a.o
After googling it, I came across this question: SFML 2.1 RenderWindow linking error
In the accepted answer, the person said that if I wanted to use g++, I had to download the "GCC" version. So, I proceeded to download the GCC - universal 32+64 bits (OS X 10.5+) version and then followed the instructions for installing and compiling SFML on linux, since there were none for mac (http://www.sfml-dev.org/tutorials/2.0/start-linux.php) by doing the following:
Since I had installed SFML in a non-standard location, I told my compiler where to find the header files like so:
-I /Users/.../Desktop/C++_Code/SMFL/SFML-2.1-osx-gcc-universal/Frameworks/SFML.framework/Headers
I also had to tell my compiler where to find the SMFL libraries:
-L /Users/.../Desktop/C++_Code/SMFL/SFML-2.1-osx-gcc-universal/lib
I needed to also tell the library loader where to find the SFML libraries from:
export LD_LIBRARY_PATH=/Users/.../Desktop/C++_Code/SMFL/SFML-2.1-osx-gcc-universal/lib
Then, I put the sfml-audio.framework, sfml-window.framework, sfml-graphics.framework, sfml-network.framework, and sfml-system.framework in my Frameworks directory (/Library/Frameworks).
Finally, I tried to compile my program in the following ways:
g++ window.cpp -I /Users/.../Desktop/C++_Code/SMFL/SFML-2.1-osx-gcc-universal/Frameworks/SFML.framework/Headers/SFML -L /users/.../Desktop/C++_Code/SMFL/SFML-2.1-osx-gcc-universal/lib -framework sfml-graphics -framework sfml-window -framework sfml-system
g++ window.cpp -framework sfml-graphics -framework sfml-window -framework sfml-system
But, I keep getting the same error. I have continued to google the error, but all I keep getting are questions where people are using Xcode and not the terminal. Any help would be greatly appreciated!
I figured it out at last! First off, as Joachim Pileborg pointed out, I need to install the clang version of SFML for mac since I was using g++ to compile which is clang++ in disguise, as Joachim Pileborg also pointed out. Next, I had to go through the instructions again for setting up SFML with Linux (http://www.sfml-dev.org/tutorials/2.0/start-linux.php).
However, the icing on the cake was when I read this question:
OSX GCC how to specify sfml library source?
...and this question:
FreeType error when building in XCode
...which got me thinking: maybe I should try moving my freetype.framework folder (which can be found in the extlibs directory) into my /Library/Frameworks directory. Once I did this and compiled using
g++ window.cpp -framework sfml-graphics -framework sfml-window -framework sfml-system
It compiled and ran successfully!!! I am very happy now!

Problems linking to SDL2 inside of Eclipse CDT on Fedora 19

I am having troubles linking SDL2 to a C++ application inside of Eclipse CDT Kepler on Fedora 19 64bit. Here is what I did:
To install SDL2 I ran the line sudo yum install SDL2-devel.i686
Created a new .cpp file with copy paste code just to test the environment from here
Add the SDL2 library to the GCC C++ Linker: Project Properties -> C/C++ Build -> Settings -> GCC C++ Linker -> Libraries -> Libraries (-l) -> add: libSDL2.so
Then when I saved and built the program I got the fallowing error:
Invoking: GCC C++ Linker
g++ -o "SDL2 Test" ./src/SDL2\ Test.o -llibSDL2.so
/usr/bin/ld: cannot find -llibSDL2.so
collect2: error: ld returned 1 exit status
make: *** [SDL2 Test] Error 1
So then I did a file system search for SDL2 and found that the libSDL2.so exists in /usr/lib/ and /lib/. Shouldn't either of those be the default location for searching for libraries? What am I missing?
(If it matters, within the .cpp file itself there are no errors, all SDL commands are recognized, it is just the linker)
I have found the answer. I am using a 64bit version of Fedora, and trying to use 32bit libraries. I assumed that because I was developing a 32bit application, that I should use 32bit libraries. But, it worked when I uninsulated the 32bit and installed the 64bit libraries.
Also, eclipse on Linux assumes that the 'lib' prefix and '.so' postfix exist, so you do not need them when you add them to the linker within eclipse (just SDL2).

GLEW: Apple Mach-O Linker (Id) Error

I'm trying to use glew in my Xcode project, but I'm getting this: Apple Mach-O Linker (Id) Error... Undefined symbols for architecture x86_64
I'm using the current version of glew that I downloaded from their sourceforge site.
Here's what I did:
Install Glew via MacPorts. (in terminal run the command sudo port install glew)
In the Xcode project's build settings add the following:
other linker flags: -lGLEW
header search paths: /opt/local/include/
library search paths: /opt/local/lib/
You aren't linking with the GLEW library. You will probably have to add the directory, you installed GLES into, it to the 'library search path' settings of the Xcode project.