GLEW: Apple Mach-O Linker (Id) Error - c++

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.

Related

Finding libgtest linker library for codeblocks ide

I am trying to run gtest on the codeblocks ide in ubuntu 17.10. It keeps coming back with undefined reference to "x" error.
After some googling it seems that that the ide is missing linker libraries for gtest. Where may I find the linker libraries for gtest?
I have installed gtest using this command:
sudo apt install libgtest-dev
and test built it using this command:
g++ -I /usr/include/gtest -I /usr/src/gtest/ -c /usr/src/gtest/src/gtest-all.cc
The linker to gtest is -lgtest wich you should add in project/build options/Linker settings -> other linker options. Make sure to select the right target (Debug/release) on the left menu.
A good step by step guide has been made here
Based on the answer by Some programmer referencing linking googletestand codeblocks
I found libgtest.a and pthread in the following directories:
/usr/lib/libgtest.a
/usr/lib/x86_64-linux-gnu/libpthread.so
I added the two files through Settings --> Compiler... --> Linker Settings
My test now compiles.

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.

Setup Xcode and FLTK

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.

Google test with Eclipse on Windows

I am trying to setup google test with Eclipse.
This is what I have done so far:
Initial Setup:
Installed CDT on Eclipse Helios.
Downloaded and installed Cygwin.
Downloaded and extracted gtest.
built gtest using cygwin make using the default makefile.
In eclipse:
Created an empty executable c++ project with Cygwin in ToolChain.
Added "[gtest_dir]\include" in C++ Build/Settings/Cygwin C++ Compiler
Added library path as "[gtest_dir]\make" under C++ Build/Settings/Cygwin C++ Linker
Builder was already GNU Make builder
Wrote some example C++ code and built project.
I am facing the following error when I build the project:
Building target: SampleCpp.exe
Invoking: Cygwin C++ Linker
g++ -L/cygdrive/d/gtest-1.7.0/make -o"SampleCpp.exe" ./src/Counter.o ./src/Counter_tests.o -lgtest
/usr/lib/gcc/i686-pc-cygwin/4.8.2/../../../../i686-pc-cygwin/bin/ld: cannot find -lgtest
collect2: error: ld returned 1 exit status
makefile:45: recipe for target 'SampleCpp.exe' failed
What am I missing?
EDIT 1 : [gtest_dir]\make contains two .a files -
gtest.a and gtest_main.a
Also I'm using Eclipse Helios
EDIT 2 :
It worked after I renamed gtest.a to gtest.lib. Is this the expected naming format for a library on Windows?
In project properties for your configuration, under C/C++ Build > Settings > Tool Settings > Cygwin C++ Linker > Miscellaneous > Other Objects, add $GTEST_DIR/make/gtest_main.a.
This makes the linker see gtest_main.a as an archive of object files, rather than a library.

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).