문제

I am trying to compile my first FLTK file. First I compiled it by gcc with -lfltk option, and I got this error:

/usr/bin/ld: /tmp/ccX7sPxQ.o: undefined reference to symbol '__gxx_personality_v0@@CXXABI_1.3'
/usr/lib/x86_64-linux-gnu/libstdc++.so.6: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status

Why do I get this error message? If I use g++ instead, it just compiles it.

edit. fltk-config --cxxflags returns:

-I/usr/include/cairo -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include 
-I/usr/include/pixman-1 -I/usr/include/freetype2 -I/usr/include/libpng12   
-I/usr/include/freetype2 -I/usr/include/cairo -I/usr/include/glib-2.0 
-I/usr/lib/x86_64-linux-gnu/glib-2.0/include -I/usr/include/pixman-1 -I/usr/include/freetype2 
-I/usr/include/libpng12    -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_THREAD_SAFE -D_REENTRANT
도움이 되었습니까?

해결책

-lfltk is not enough to build a minimal FLTK-based application.

I strongly suggest you to read the following page: http://www.fltk.org/doc-1.3/basics.html . It clearly explains how to compile a simple FLTK program.

Assuming your FLTK application is not using extra FLTK libraries (opengl, images, forms) and is in a single file, called myfltkapp.cpp, the absolutely quickest way to compile and link it properly would be:

fltk-config --compile myfltkapp.cpp

다른 팁

I guess the reason I got the error comes from the difference between gcc and g++. I thought I could compile it by gcc with fltk library, but gcc does not link c++ standard library automatically. Thus you have to include the C++ standard library for gcc. It was a silly question.

gcc myfltkapp.cpp -lstdc++ -lfltk

What is the difference between g++ and gcc?

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top