I'm currently learning c++ with the book Programming: Principles and Practice Using C++ from Stroustrup and am in chapter 12. I'm now trying since days to get FLTK with the specific headers working.
I have installed FLTK with MacPorts. When i'm trying to compile the code including Simple_window.h, i get the following errors:
bash-3.2# fltk-config --compile main.cpp
/usr/bin/g++-4.2 -arch i386 -I/opt/local/include -pipe -arch i386 -arch i386
-D_THREAD_SAFE -D_REENTRANT -o main main.cpp -arch i386 -arch i386
/opt/local/lib/libfltk.a -lpthread -framework Carbon -framework
ApplicationServices
Undefined symbols:
"vtable for Graph_lib::Window", referenced from:
__ZTVN9Graph_lib6WindowE$non_lazy_ptr in cc1oxcSA.o
(maybe you meant: __ZTVN9Graph_lib6WindowE$non_lazy_ptr)
"vtable for Graph_lib::Button", referenced from:
__ZTVN9Graph_lib6ButtonE$non_lazy_ptr in cc1oxcSA.o
(maybe you meant: __ZTVN9Graph_lib6ButtonE$non_lazy_ptr)
"Simple_window::Simple_window(Point, int, int, String const&)", referenced from:
_main in cc1oxcSA.o
"Graph_lib::Window::draw()", referenced from:
vtable for Simple_windowin cc1oxcSA.o
"typeinfo for Graph_lib::Window", referenced from:
typeinfo for Simple_windowin cc1oxcSA.o
ld: symbol(s) not found
collect2: ld returned 1 exit status
I have no idea what this means. I read the answers here (SO). I created the .o files. I'm trying to compile this on Mac OS with fltk-config.
It seems to me that there should be a -l (dash ell) in front of /opt/local/lib/libfltk.a when you invoke the compiler. Or you could replace /opt/local/lib/libfltk.a with -L/opt/local/lib -lfltk which might be more conventional.
I got the FLTK program '12.3 A first example' working on Linux using the following steps:
Download Programming-code.zip from the author's website
then unzip it and go to the Programming-code/GUI folder.
In that folder, add #include <cstdlib> to the file std_lib_facilities.h to avoid an atoi not declared error in the next step
Run make at the command line in the Programming-code/GUI folder. This should create the file libbookgui.a.
Assuming the program is named Example.cpp, run the following command:
gcc `fltk-config --use-forms --use-gl --use-images --ldflags`Example.cpp libbookgui.a
Run the a.out executable
Using a sample program from source code found in a PDF FLTK-Tutorial.pdf
I had to add the following lines to get a clean compile in my Ubuntu Linux.
// 3 includes just below are not in the example but are required
// for a clean compile
#include <Fl/x.H>
#include <stdlib.h>
#include <stdio.h>
You must configure your compile line correctly. FLTK has fltk-config tool to help with the configuration.
fltk-config
to get the help message for fltk-config. Read the output to determine what you need to put in for the compile, the link, and any of the compatibility (gl, glut, forms, etc.) for packages you are using.
Copy this information into your compile command.
You can also use the --compile prgrname.cxx switch to compile directly. Include -g because you will want gdb support.
For example:
fltk-config --cxxflags --ldflags
Gives (for me):
-I/usr/include/freetype2 -g -O2 -D_THREAD_SAFE -D_REENTRANT -Wl,-Bsymbolic-functions -lfltk
Add an output name and the input programs:
gcc -I/usr/include/freetype2 -g -O2 -D_THREAD_SAFE -D_REENTRANT -Wl,-Bsymbolic-functions -lfltk mousedrawtest.cpp mousedraw.cpp -o b.out
While there is less to learn for FLTK, it is not for the faint of heart. Erco's (Greg Ercolano) tutorials are excellent and sample code for many common challenges. http://seriss.com/people/erco/fltk/
http://www.fltk.org/documentation.php/doc-1.1/basics.html
There are a number of other good ones search: FLTK tutorial
When converting from simple sample programs to a real object oriented model, keep in mind scope, particularly for the top level window and its contents.
Today, Wednesday, I know much more about gdb, scope, and namespace than I did on Monday.
Related
Trying to compile code on OSX 10.15. which perfectly works on OSX 10.12 and got stuck. Quite familiar with general concept of linking and problem solving with undefined symbols as very well described here. Using command line tools only, libtool and clang++ are provided by Xcode. Seems to be a problem with my local OSX CLT chain. Tried reinstallation of full Xcode.
Compiling files with:
clang++ -g -Wall -arch x86_64 -o ./Permutation.o Permutation.cpp
clang++ -g -Wall -arch x86_64 -o ./MarchingCubes.o MarchingCubes.cpp
Then linking into shared library with:
libtool -install_name #rpath/libmodelling.dylib -dynamic -L../../../release/lib/ -lstdc++ -lpthread -lz -lm Permutation.o MarchingCubes.o -o ../../../release/lib//libmodelling.dylib
Resulting in
Undefined symbols for architecture x86_64:
"__Unwind_Resume", referenced from:
__ZN13MarchingCubesD2Ev in MarchingCubes.o
Tried several hints from similar questions on stackoverflow such as:
Setting -mmacosx-version-min=10.9, changing -lstdc++ against -lc++, trying g++ face of clang++
libunwind.dylib providing the "undefined symbol" lives in /usr/lib/system on my system which should be found via the umbrella framework System which again the compiler should figure out by himself if correctly understood.
thankful for any suggestion
When I try to compile the newly installed package MPFR I get the following error:
Undefined symbols for architecture x86_64:
"_mpfr_init2", referenced from:
_main in main.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
I use Codelite on a macbook pro and I think I successfully installed the package using the instruction on the website.
Any ideas on how to solve it?
From the limited information given, I suspect that you are not linking the MPFR library during the linking phase of main.cpp. What is the exact command you are using?
Make sure that -lmpfr is passed at the end of the clang++ command, like so:
clang++ main.cpp -lmpfr
or:
clang++ main.cpp -c
clang++ main.o -lmpfr
If libmpfr.so is installed in a nonstandard place, then you need to tell the compiler where, using the -L option:
clang++ main.cpp -L"$MPFR_PATH" -lmpfr
or:
clang++ main.cpp -c
clang++ main.o -L"$MPFR_PATH" -lmpfr
If not, then please provide more information.
I'm having difficulties using my built Lua.
To build my small project, I'm using:
gcc -m32 -arch i386 -I ~/Documents/lua-5.1.4/include -L ~/Documents/lua-5.1.4/lib -llua -mconsole -sectcreate __TEXT __info_plist ./Info.plist -o LuaProject -masm=intel LuaProject.cpp
I built Lua with "make macosx test". To try to make it build 32-bit, I modified the src/Makefile so that the top became:
CC= gcc
CFLAGS= -m32 -arch i386 -O2 -Wall $(MYCFLAGS)
AR= ar rcu
RANLIB= ranlib
RM= rm -f
LIBS= -lm $(MYLIBS)
MYCFLAGS=
MYLDFLAGS= -m32 -arch i386
MYLIBS=
That seemed to make it for 32-bit. All I did was add -m32 -arch i386 to CFLAGS (MYCFLAGS wasn't affecting anything) and -m32 -archi386 to MYLDFLAGS. After it worked for neither -m32 nor -arch i386 individually I added both (perhaps not the best logic) which changed nothing. The build works, so then I "sudo make install local", which creates the nice folders I used to try to compile my project.
The output from gcc ends up being:
Undefined symbols for architecture i386:
"luaL_newstate()", referenced from:
_main in LuaProject-15f700.o
"luaL_openlibs(lua_State*)", referenced from:
_main in LuaProject-15f700.o
"luaL_loadbuffer(lua_State*, char const*, unsigned long, char const*)", referenced from:
_main in LuaProject-15f700.o
"lua_pcall(lua_State*, int, int, int)", referenced from:
_main in LuaProject-15f700.o
ld: symbol(s) not found for architecture i386
I am hopefully including all I need to (lua.h, lauxlib.h, lualib.h) and no errors are thrown about the -llua itself, so I am confused as to why this isn't working.
I didn't want to clutter the question with the full Lua makefile but I can upload it if needed.
I'm trying to build multithread supporting xgboost according to this guide.
So i made fist three steps. But when i run:
cd xgboost
make
i get this message:
/Users/user/clang-omp/build/bin/clang++ -c -Wall -O3 -msse2 -Wno-unknown-pragmas -funroll-loops -fopenmp -fopenmp -fPIC -o updater.o src/tree/updater.cpp
src/tree/updater.cpp:5:10: fatal error: 'cstring' file not found
#include <cstring>
^
1 error generated.
make: *** [updater.o] Error 1
What am i doing wrong?
System:
Mac OS X 10.10.4
P.S. I've tried to set system variables like in this post, but it didn't work.
Solved:
Just found file "cstring" on my mac. There were some variants. I took folder:/usr/local/Cellar/clang-omp/2015-04-01/libexec/include/c++/v1/
and set variables:
export CPLUS_INCLUDE_PATH=/usr/local/Cellar/clang-omp/2015-04-01/libexec/include/c++/v1/:
export C_INCLUDE_PATH=/usr/local/Cellar/clang-omp/2015-04-01/libexec/include/c++/v1/:
It wasn't the end of the story. Another mistake occured:
Undefined symbols for architecture x86_64:
"__ZNKSs7compareEPKc", referenced from:
__ZN7xgboost14BoostLearnTask3RunEiPPc in main.o
__ZN7xgboost7learner12BoostLearner10InitObjGBMEv in main.o
__ZN7xgboost14BoostLearnTask8InitDataEv in main.o
...
Solved in this post.
So I just correct Makefile like this:
export CC = clang-omp++
export CXX = clang-omp++
And it's worked.
I'm sorry to ask a question that resurfaces all over the place in different forms, but this has me tearing my hair out and I've tried every suggestion from all the dark corners of the internet.
I'm trying to use the Wt framework (for web based c++ applications) with Xcode. Its header files are at /usr/local/include and its library files (and boost's) are at /usr/local/lib. I can compile at the terminal with
gcc -o hello testWt.cpp -lstdc++ -lwt.3.3.0 -lwthttp.3.3.0 -lboost_random -lboost_regex -lboost_signals -lboost_system -lboost_thread -lboost_filesystem -lboost_program_options -lboost_date_time
but within Xcode I've had no luck. I've tried:
Adding -I/usr/local/include to the OTHER_C++_FLAGS option
Adding /usr/local/lib to the Library Search Paths option
Adding /usr/local/include to Header Search Paths
Dragging all the libraries (both the .dylib and/or the .a versions) into the "Link Binary with Libraries" section
All combinations of the above
Now, I'm bashing my head against this linker error:
Ld /Users/charles/Library/Developer/Xcode/DerivedData/Test-dzrqjofmpnjowvcwtscacpwnhtqw/Build/Products/Debug/Test normal x86_64
cd /Users/charles/tmp/Test
setenv MACOSX_DEPLOYMENT_TARGET 10.7
/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.8.sdk -L/Users/charles/Library/Developer/Xcode/DerivedData/Test-dzrqjofmpnjowvcwtscacpwnhtqw/Build/Products/Debug -L/usr/local/lib -F/Users/charles/Library/Developer/Xcode/DerivedData/Test-dzrqjofmpnjowvcwtscacpwnhtqw/Build/Products/Debug -filelist /Users/charles/Library/Developer/Xcode/DerivedData/Test-dzrqjofmpnjowvcwtscacpwnhtqw/Build/Intermediates/Test.build/Debug/Test.build/Objects-normal/x86_64/Test.LinkFileList -mmacosx-version-min=10.7 -stdlib=libc++ -lwt.3.3.0 -lwthttp.3.3.0 -lboost_atomic -lboost_chrono -lboost_context -lboost_date_time -lboost_exception -lboost_filesystem -lboost_graph -lboost_iostreams -lboost_locale -lboost_math_c99 -lboost_math_c99f -lboost_math_c99l -lboost_math_tr1 -lboost_math_tr1f -lboost_math_tr1l -lboost_prg_exec_monitor -lboost_program_options -lboost_python -lboost_random -lboost_regex -lboost_serialization -lboost_signals -lboost_system -lboost_test_exec_monitor -lboost_thread -lboost_timer -lboost_unit_test_framework -lboost_wave -lboost_wserialization -o /Users/charles/Library/Developer/Xcode/DerivedData/Test-dzrqjofmpnjowvcwtscacpwnhtqw/Build/Products/Debug/Test
Undefined symbols for architecture x86_64:
"Wt::WApplication::makeAbsoluteUrl(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) const", referenced from:
vtable for HelloApplication in main.o
ld: symbol(s) not found for architecture x86_64
Further than this I cannot get. This is the first time I've used Xcode for development so I may be missing something obvious; I'd be incredibly grateful if someone could point it out!
OK I finally got it. It turns out that the problem was that my program is written using the libc++ libraries whereas the Wt library was built using the older libstdc++.
To fix this, I recompiled boost and Wt using libc++ instead by changing their CMakeLists.txt file, adding the line set(CMAKE_CXX_FLAGS "-std=c++11 -stdlib=libc++"). This produced a tonne of warnings, but seemed to work.
After installing these new builds, I made sure that Xcode had -L/usr/local/lib -I/usr/local/include in its Other C++ Flags options and /usr/local/include & /usr/local/lib in 'Header Search Paths' and 'Library Search Paths' respectively. Then, I added the libraries into the "Link Binaries with Library" section. This solved my problem.