How to link sfml 2 dynamicaly in eclipse cdt? - c++

I've just installed Eclipse CDT and tryied to install sfml 2 in it. I seem to have a problem at linking the libs as it won't compile neither with static or dynamic linking. It just gives me these errors:
22:08:57 **** Incremental Build of configuration Debug for project sdl ****
Info: Internal Builder is used for build
g++ "-LC:\\Users\\Romeo\\Desktop\\SFML-2.0-rc\\lib" -o sdl.exe "src\\sdl.o" -lsfml-graphics-s-d -lsfml-window-s-d -lsfml-system-s-d
src\sdl.o: In function `main':
D:\_workspace\_eclipsec++\sdl\Debug/../src/sdl.cpp:5: undefined reference to `sf::VideoMode::VideoMode(unsigned int, unsigned int, unsigned int)'
D:\_workspace\_eclipsec++\sdl\Debug/../src/sdl.cpp:5: undefined reference to `sf::RenderWindow::RenderWindow(sf::VideoMode, std::string const&, unsigned int, sf::ContextSettings const&)'
D:\_workspace\_eclipsec++\sdl\Debug/../src/sdl.cpp:6: undefined reference to `sf::CircleShape::CircleShape(float, unsigned int)'
D:\_workspace\_eclipsec++\sdl\Debug/../src/sdl.cpp:7: undefined reference to `sf::Color::Green'
D:\_workspace\_eclipsec++\sdl\Debug/../src/sdl.cpp:7: undefined reference to `sf::Shape::setFillColor(sf::Color const&)'
D:\_workspace\_eclipsec++\sdl\Debug/../src/sdl.cpp:15: undefined reference to `sf::Window::close()'
D:\_workspace\_eclipsec++\sdl\Debug/../src/sdl.cpp:12: undefined reference to `sf::Window::pollEvent(sf::Event&)'
D:\_workspace\_eclipsec++\sdl\Debug/../src/sdl.cpp:18: undefined reference to `sf::Color::Color(unsigned char, unsigned char, unsigned char, unsigned char)'
D:\_workspace\_eclipsec++\sdl\Debug/../src/sdl.cpp:18: undefined reference to `sf::RenderTarget::clear(sf::Color const&)'
D:\_workspace\_eclipsec++\sdl\Debug/../src/sdl.cpp:19: undefined reference to `sf::RenderStates::Default'
D:\_workspace\_eclipsec++\sdl\Debug/../src/sdl.cpp:19: undefined reference to `sf::RenderTarget::draw(sf::Drawable const&, sf::RenderStates const&)'
D:\_workspace\_eclipsec++\sdl\Debug/../src/sdl.cpp:20: undefined reference to `sf::Window::display()'
D:\_workspace\_eclipsec++\sdl\Debug/../src/sdl.cpp:9: undefined reference to `sf::Window::isOpen() const'
D:\_workspace\_eclipsec++\sdl\Debug/../src/sdl.cpp:5: undefined reference to `sf::RenderWindow::~RenderWindow()'
D:\_workspace\_eclipsec++\sdl\Debug/../src/sdl.cpp:5: undefined reference to `sf::RenderWindow::~RenderWindow()'
D:\_workspace\_eclipsec++\sdl\Debug/../src/sdl.cpp:5: undefined reference to `sf::RenderWindow::~RenderWindow()'
src\sdl.o: In function `~CircleShape':
C:/Users/Romeo/Desktop/SFML-2.0-rc/include/SFML/Graphics/CircleShape.hpp:41: undefined reference to `vtable for sf::CircleShape'
C:/Users/Romeo/Desktop/SFML-2.0-rc/include/SFML/Graphics/CircleShape.hpp:41: undefined reference to `vtable for sf::CircleShape'
C:/Users/Romeo/Desktop/SFML-2.0-rc/include/SFML/Graphics/CircleShape.hpp:41: undefined reference to `sf::Shape::~Shape()'
collect2: ld returned 1 exit status
22:08:59 Build Finished (took 1s.419ms)
I think i'm doing something wrong but i can't figure out what. A little help?

Because your g++ is different from the compiler to build sfml. Any following combination will cause your problem:
g++ <-> cl(vc++'s compiler)
g++32 <-> g++64
g++ <-> gcc

Related

G++ undefined references for libuvc and opencv2

I'm trying to compile a C++ program which includes the libuvc.h header file and some more header files of opencv2.
The problem is, that I'm getting the following errors (undefinded references):
root#Raspi_DataHarvest:~/Schreibtisch# g++ UVCCameraHandler.cpp -I/usr/local/include/libuvc -I/usr/local/include/opencv2
/tmp/ccvQZdkd.o: In function `UVCCameraHandler::start(int, CameraProperties, int)':
UVCCameraHandler.cpp:(.text+0x164): undefined reference to `uvc_init'
UVCCameraHandler.cpp:(.text+0x184): undefined reference to `uvc_perror'
UVCCameraHandler.cpp:(.text+0x204): undefined reference to `uvc_get_device_descriptor'
UVCCameraHandler.cpp:(.text+0x334): undefined reference to `uvc_open'
UVCCameraHandler.cpp:(.text+0x354): undefined reference to `uvc_perror'
UVCCameraHandler.cpp:(.text+0x3a8): undefined reference to `uvc_get_stream_ctrl_format_size'
UVCCameraHandler.cpp:(.text+0x3e8): undefined reference to `uvc_get_stream_ctrl_format_size'
UVCCameraHandler.cpp:(.text+0x40c): undefined reference to `uvc_print_diag'
UVCCameraHandler.cpp:(.text+0x424): undefined reference to `uvc_print_stream_ctrl'
UVCCameraHandler.cpp:(.text+0x43c): undefined reference to `uvc_perror'
UVCCameraHandler.cpp:(.text+0x46c): undefined reference to `uvc_stream_open_ctrl'
UVCCameraHandler.cpp:(.text+0x48c): undefined reference to `uvc_stream_start_iso'
UVCCameraHandler.cpp:(.text+0x4a4): undefined reference to `uvc_perror'
/tmp/ccvQZdkd.o: In function `UVCCameraHandler::grabFramesGrayscale(cv::Mat&, cv::Mat&)':
UVCCameraHandler.cpp:(.text+0x5c8): undefined reference to `uvc_stream_get_frame'
/tmp/ccvQZdkd.o: In function `UVCCameraHandler::grabFramesColor(cv::Mat&, cv::Mat&)':
UVCCameraHandler.cpp:(.text+0x864): undefined reference to `uvc_stream_get_frame'
UVCCameraHandler.cpp:(.text+0x92c): undefined reference to `cv::cvtColor(cv::_InputArray const&, cv::_OutputArray const&, int, int)'
/tmp/ccvQZdkd.o: In function `UVCCameraHandler::uvcFindDevice(uvc_context*, uvc_device**, int, int, char const*, int)':
UVCCameraHandler.cpp:(.text+0xae0): undefined reference to `uvc_get_device_list'
UVCCameraHandler.cpp:(.text+0xb10): undefined reference to `uvc_get_device_descriptor'
UVCCameraHandler.cpp:(.text+0xd0c): undefined reference to `uvc_get_device_descriptor'
/tmp/ccvQZdkd.o: In function `UVCCameraHandler::setProperties(CameraProperties)':
UVCCameraHandler.cpp:(.text+0xfb0): undefined reference to `uvc_get_gain'
UVCCameraHandler.cpp:(.text+0xff8): undefined reference to `uvc_set_gain'
UVCCameraHandler.cpp:(.text+0x103c): undefined reference to `uvc_set_ae_mode'
UVCCameraHandler.cpp:(.text+0x1050): undefined reference to `uvc_set_exposure_abs'
UVCCameraHandler.cpp:(.text+0x1068): undefined reference to `uvc_set_ae_mode'
/tmp/ccvQZdkd.o: In function `cv::String::String(char const*)':
UVCCameraHandler.cpp:(.text._ZN2cv6StringC2EPKc[_ZN2cv6StringC5EPKc]+0x60): undefined reference to `cv::String::allocate(unsigned int)'
/tmp/ccvQZdkd.o: In function `cv::String::~String()':
UVCCameraHandler.cpp:(.text._ZN2cv6StringD2Ev[_ZN2cv6StringD5Ev]+0x14): undefined reference to `cv::String::deallocate()'
/tmp/ccvQZdkd.o: In function `cv::String::operator=(cv::String const&)':
UVCCameraHandler.cpp:(.text._ZN2cv6StringaSERKS0_[_ZN2cv6StringaSERKS0_]+0x30): undefined reference to `cv::String::deallocate()'
/tmp/ccvQZdkd.o: In function `cv::Mat::Mat(cv::Size_<int>, int, void*, unsigned int)':
UVCCameraHandler.cpp:(.text._ZN2cv3MatC2ENS_5Size_IiEEiPvj[_ZN2cv3MatC5ENS_5Size_IiEEiPvj]+0x140): undefined reference to `cv::error(int, cv::String const&, char const*, char const*, int)'
UVCCameraHandler.cpp:(.text._ZN2cv3MatC2ENS_5Size_IiEEiPvj[_ZN2cv3MatC5ENS_5Size_IiEEiPvj]+0x244): undefined reference to `cv::error(int, cv::String const&, char const*, char const*, int)'
/tmp/ccvQZdkd.o: In function `cv::Mat::~Mat()':
UVCCameraHandler.cpp:(.text._ZN2cv3MatD2Ev[_ZN2cv3MatD5Ev]+0x3c): undefined reference to `cv::fastFree(void*)'
/tmp/ccvQZdkd.o: In function `cv::Mat::operator=(cv::Mat const&)':
UVCCameraHandler.cpp:(.text._ZN2cv3MataSERKS0_[_ZN2cv3MataSERKS0_]+0x140): undefined reference to `cv::Mat::copySize(cv::Mat const&)'
/tmp/ccvQZdkd.o: In function `cv::Mat::create(int, int, int)':
UVCCameraHandler.cpp:(.text._ZN2cv3Mat6createEiii[_ZN2cv3Mat6createEiii]+0xc4): undefined reference to `cv::Mat::create(int, int const*, int)'
/tmp/ccvQZdkd.o: In function `cv::Mat::release()':
UVCCameraHandler.cpp:(.text._ZN2cv3Mat7releaseEv[_ZN2cv3Mat7releaseEv]+0x68): undefined reference to `cv::Mat::deallocate()'
/tmp/ccvQZdkd.o: In function `cv::Mat::operator()(cv::Rect_<int> const&) const':
UVCCameraHandler.cpp:(.text._ZNK2cv3MatclERKNS_5Rect_IiEE[_ZNK2cv3MatclERKNS_5Rect_IiEE]+0x24): undefined reference to `cv::Mat::Mat(cv::Mat const&, cv::Rect_<int> const&)'
collect2: error: ld returned 1 exit status
So, this looks to me like g++ does not find the location of the header files, but they are installed in the correct directory!
root#Raspi_DataHarvest:~# find / | grep libuvc.h
/usr/local/include/libuvc/libuvc.h
root#Raspi_DataHarvest:~# find / | grep opencv2/opencv.hpp
/usr/local/include/opencv2/opencv.hpp
Furthermore, there's no effect using the absolute paths, like:
#include "/usr/local/include/libuvc.h"
...
Does anyone know how to solve the reference errors?
Try
g++ UVCCameraHandler.cpp -I/usr/local/include/libuvc -I/usr/local/include/opencv2 -luvc -lopencv
The most preferable
g++ UVCCameraHandler.cpp `pkg-config --libs --cflags opencv` `pkg-config --libs --cflags lubuvc`
Building a C++ program is a three-step process:
Editing the source
Compiling the source files into object files
Linking the object files into the final executable
Modern compilers often use front-end programs (like e.g. GCC with the g++ program) that combine steps 2 and 3 into a single action.
In step 2 above, the header files are included.
In step 3 you need to link with the actual libraries. You do not do this, so the linker will complain that it can't find the functions you use.
Linking with the libraries using GCC is done with the -l (lower-case L) option, listing the library name. Like for example -lopencv to link with the OpenCV library.
If the libraries are in a non-standard location (which /usr/local/lib usually is) then you need to tell the linker where to find the libraries as well. This is done with the -L option, similar to the -I option you already use to tell the compiler where to search for header-files. For example -L/usr/local/lib.
You need to link against the correct libraries (assuming your libs are in /usr/local/lib):
g++ UVCCameraHandler.cpp -I/usr/local/include/libuvc -I/usr/local/include/opencv2 -L/usr/local/lib -luvc -lopencv_core

g++ when compile and link multiple files

I encounter g++ compile/link problem.
I want to implement a Dynamic Array.
I separated my class definition and implementation into "DArray.h" and "DArray.cpp" files.
And do test in "DArraytest.cpp" file within which contains a main functionn.
all there files are in same directory, and I use the following command to compile
g++ *.cpp
but it still gives me such link error
/tmp/cc4tu73o.o: In function __static_initialization_and_destruction_0(int, int)':
DArray.cpp:(.text+0x1d): undefined reference tostd::ios_base::Init::Init()'
DArray.cpp:(.text+0x34): undefined reference to std::ios_base::Init::~Init()'
/tmp/ccdHUZjJ.o: In functionmain':
DArraytest.cpp:(.text+0x12): undefined reference to DArray<int>::DArray()'
DArraytest.cpp:(.text+0x2e): undefined reference toDArray::append(int const&)'
DArraytest.cpp:(.text+0x4a): undefined reference to DArray<int>::append(int const&)'
DArraytest.cpp:(.text+0x66): undefined reference toDArray::append(int const&)'
DArraytest.cpp:(.text+0x82): undefined reference to DArray<int>::append(int const&)'
DArraytest.cpp:(.text+0xa3): undefined reference tostd::cout'
DArraytest.cpp:(.text+0xa8): undefined reference to std::ostream::operator<<(int)'
DArraytest.cpp:(.text+0xb0): undefined reference tostd::basic_ostream >& std::endl >(std::basic_ostream >&)'
DArraytest.cpp:(.text+0xb8): undefined reference to std::ostream::operator<<(std::ostream& (*)(std::ostream&))'
DArraytest.cpp:(.text+0xc9): undefined reference toDArray::~DArray()'
DArraytest.cpp:(.text+0xeb): undefined reference to DArray<int>::~DArray()'
/tmp/ccdHUZjJ.o: In function__static_initialization_and_destruction_0(int, int)':
DArraytest.cpp:(.text+0x11d): undefined reference to std::ios_base::Init::Init()'
DArraytest.cpp:(.text+0x134): undefined reference tostd::ios_base::Init::~Init()'
/tmp/ccdHUZjJ.o:(.eh_frame+0x13): undefined reference to `__gxx_personality_v0'
collect2: error: ld returned 1 exit status
Can someone help me
I think you need to provide all the .cpp file names to g++. To avoid this you can create a makefile which can automatically apply same compilation rule to all .cpp files

compile ExcelFormat Library

Could someone tell me how to solve this issue. I'm trying to compile this library here:
http://www.codeproject.com/Articles/42504/ExcelFormat-Library
I'm doing: g++ Examples.cpp
gcc version 4.6.3 (Ubuntu/Linaro 4.6.3-1ubuntu5)
If my question is to easy/basic/simple/os dependent... please tell recommend me a book or two that I should read first in order to be able to figure out an answer for this question.
Here's the error message:
/tmp/cczceVBy.o: In function example1(char const*)':
Examples.cpp:(.text+0x2d): undefined reference toYExcel::BasicExcel::BasicExcel()'
Examples.cpp:(.text+0x41): undefined reference to YExcel::BasicExcel::New(int)'
Examples.cpp:(.text+0x55): undefined reference toYExcel::BasicExcel::GetWorksheet(int)'
Examples.cpp:(.text+0x75): undefined reference to ExcelFormat::XLSFormatManager::XLSFormatManager(YExcel::BasicExcel&)'
Examples.cpp:(.text+0xf2): undefined reference toYExcel::BasicExcelWorksheet::Cell(int, int)'
Examples.cpp:(.text+0x10d): undefined reference to YExcel::BasicExcelCell::Set(char const*)'
Examples.cpp:(.text+0x166): undefined reference toYExcel::BasicExcelWorksheet::Cell(int, int)'
Examples.cpp:(.text+0x173): undefined reference to YExcel::BasicExcelCell::Set(char const*)'
Examples.cpp:(.text+0x287): undefined reference toYExcel::BasicExcelWorksheet::Cell(int, int)'
Examples.cpp:(.text+0x2a2): undefined reference to YExcel::BasicExcelCell::Set(char const*)'
Examples.cpp:(.text+0x2df): undefined reference toYExcel::BasicExcelWorksheet::Cell(int, int)'
---- snip many more of the same kind -----
collect2: ld returned 1 exit status
Use BasicExcel.Cpp and BasicExcel.hpp file in your project directory which comes with the Excelformat zip file.

Boost C++ code not building, can someone help me with library linking?

I've followed the tutorial from here to set up my Eclipse installation with Boost and the examples at the bottom of the tutorial to test the compilation work. I'm trying to use asio for sockets, but I'm receiving the following when compiling:
**** Build of configuration Debug for project Client ****
**** Internal Builder is used for build ****
g++ -IC:\MinGW\Boost\include\boost-1_53 -O0 -g3 -Wall -c -fmessage-length=0 -o src\Client.o ..\src\Client.cpp
g++ -LC:\MinGW\Boost\lib -o Client.exe src\Client.o
src\Client.o: In function `__static_initialization_and_destruction_0':
C:/MinGW/Boost/include/boost-1_53/boost/system/error_code.hpp:214: undefined reference to `boost::system::generic_category()'
C:/MinGW/Boost/include/boost-1_53/boost/system/error_code.hpp:215: undefined reference to `boost::system::generic_category()'
C:/MinGW/Boost/include/boost-1_53/boost/system/error_code.hpp:216: undefined reference to `boost::system::system_category()'
src\Client.o: In function `boost::system::error_code::error_code()':
C:/MinGW/Boost/include/boost-1_53/boost/system/error_code.hpp:315: undefined reference to `boost::system::system_category()'
src\Client.o: In function `boost::asio::error::get_system_category()':
C:/MinGW/Boost/include/boost-1_53/boost/asio/error.hpp:216: undefined reference to `boost::system::system_category()'
src\Client.o: In function `boost::asio::detail::winsock_init_base::startup(boost::asio::detail::winsock_init_base::data&, unsigned char, unsigned char)':
C:/MinGW/Boost/include/boost-1_53/boost/asio/detail/impl/winsock_init.ipp:39: undefined reference to `__imp_WSAStartup'
src\Client.o: In function `boost::asio::detail::winsock_init_base::cleanup(boost::asio::detail::winsock_init_base::data&)':
C:/MinGW/Boost/include/boost-1_53/boost/asio/detail/impl/winsock_init.ipp:48: undefined reference to `__imp_WSACleanup'
src\Client.o: In function `boost::asio::detail::socket_ops::clear_last_error()':
C:/MinGW/Boost/include/boost-1_53/boost/asio/detail/impl/socket_ops.ipp:51: undefined reference to `__imp_WSASetLastError'
src\Client.o: In function `boost::asio::detail::socket_ops::close(unsigned long long, unsigned char&, bool, boost::system::error_code&)':
C:/MinGW/Boost/include/boost-1_53/boost/asio/detail/impl/socket_ops.ipp:297: undefined reference to `__imp_closesocket'
C:/MinGW/Boost/include/boost-1_53/boost/asio/detail/impl/socket_ops.ipp:314: undefined reference to `__imp_ioctlsocket'
C:/MinGW/Boost/include/boost-1_53/boost/asio/detail/impl/socket_ops.ipp:329: undefined reference to `__imp_closesocket'
src\Client.o: In function `boost::asio::detail::socket_ops::recv(unsigned long long, _WSABUF*, unsigned long long, int, boost::system::error_code&)':
C:/MinGW/Boost/include/boost-1_53/boost/asio/detail/impl/socket_ops.ipp:683: undefined reference to `__imp_WSARecv'
src\Client.o: In function `boost::asio::detail::socket_ops::send(unsigned long long, _WSABUF const*, unsigned long long, int, boost::system::error_code&)':
C:/MinGW/Boost/include/boost-1_53/boost/asio/detail/impl/socket_ops.ipp:1066: undefined reference to `__imp_WSASend'
src\Client.o: In function `boost::asio::detail::socket_ops::socket(int, int, int, boost::system::error_code&)':
C:/MinGW/Boost/include/boost-1_53/boost/asio/detail/impl/socket_ops.ipp:1294: undefined reference to `__imp_WSASocketA'
C:/MinGW/Boost/include/boost-1_53/boost/asio/detail/impl/socket_ops.ipp:1305: undefined reference to `__imp_setsockopt'
src\Client.o: In function `boost::asio::detail::socket_ops::poll_read(unsigned long long, unsigned char, boost::system::error_code&)':
C:/MinGW/Boost/include/boost-1_53/boost/asio/detail/impl/socket_ops.ipp:1716: undefined reference to `__imp_select'
src\Client.o: In function `boost::asio::detail::socket_ops::poll_connect(unsigned long long, boost::system::error_code&)':
C:/MinGW/Boost/include/boost-1_53/boost/asio/detail/impl/socket_ops.ipp:1797: undefined reference to `__imp_select'
src\Client.o: In function `boost::asio::detail::socket_ops::translate_addrinfo_error(int)':
C:/MinGW/Boost/include/boost-1_53/boost/asio/detail/impl/socket_ops.ipp:2869: undefined reference to `__imp_WSAGetLastError'
src\Client.o: In function `boost::asio::detail::socket_ops::getaddrinfo(char const*, char const*, addrinfo const&, addrinfo**, boost::system::error_code&)':
C:/MinGW/Boost/include/boost-1_53/boost/asio/detail/impl/socket_ops.ipp:2887: undefined reference to `__imp_getaddrinfo'
src\Client.o: In function `boost::asio::detail::socket_ops::freeaddrinfo(addrinfo*)':
C:/MinGW/Boost/include/boost-1_53/boost/asio/detail/impl/socket_ops.ipp:2930: undefined reference to `__imp_freeaddrinfo'
src\Client.o: In function `unsigned long long boost::asio::detail::socket_ops::error_wrapper<unsigned long long>(unsigned long long, boost::system::error_code&)':
C:/MinGW/Boost/include/boost-1_53/boost/asio/detail/impl/socket_ops.ipp:62: undefined reference to `__imp_WSAGetLastError'
src\Client.o: In function `int boost::asio::detail::socket_ops::error_wrapper<int>(int, boost::system::error_code&)':
C:/MinGW/Boost/include/boost-1_53/boost/asio/detail/impl/socket_ops.ipp:62: undefined reference to `__imp_WSAGetLastError'
src\Client.o: In function `int boost::asio::detail::socket_ops::call_connect<int>(int boost::asio::detail::socket_ops::msghdr::*, unsigned long long, sockaddr const*, unsigned long long)':
C:/MinGW/Boost/include/boost-1_53/boost/asio/detail/impl/socket_ops.ipp:452: undefined reference to `__imp_connect'
src\Client.o: In function `int boost::asio::detail::socket_ops::call_setsockopt<int>(int boost::asio::detail::socket_ops::msghdr::*, unsigned long long, int, int, void const*, unsigned long long)':
C:/MinGW/Boost/include/boost-1_53/boost/asio/detail/impl/socket_ops.ipp:1340: undefined reference to `__imp_setsockopt'
src\Client.o: In function `int boost::asio::detail::socket_ops::call_getsockopt<int>(int boost::asio::detail::socket_ops::msghdr::*, unsigned long long, int, int, void*, unsigned long long*)':
C:/MinGW/Boost/include/boost-1_53/boost/asio/detail/impl/socket_ops.ipp:1426: undefined reference to `__imp_getsockopt'
collect2.exe: error: ld returned 1 exit status
Build error occurred, build is stopped
Time consumed: 4033 ms.
I'm assuming I've gone wrong somewhere when linking the libraries. Could somebody please explain what the author of that tutorial meant by
Under libraries, add the specific boost libraries you need.
For example I have added:
boost_thread-mgw47-mt-d-1_52
boost_system-mgw47-mt-d-1_52
and explain (in detail) how to go about this in Eclipse please (for both Debug and Release)? Thanks.
Oh and if you want the code, it's simply the code found here.
The errors you get are indeed linking errors, because of missing libraries (probably the ones you list).
A quick search led to these two SO entries:
How to add a library to eclipse c project
C++: external library in CDT
Note that in certain versions of eclipse/CDT there's a Library tab in the symbols & path configuration window, but it doesn't seem to be present in all versions, so you must resort to the linker configuration panel as explained in the answers linked above.
If you went through the previous tutorial from the same site you link in your question (the one about setting up eclipse and cdt), and managed to get the sample programme compiled, then the 2 boost libraries are the only missing. Otherwise, you might need to add a few others (some of the missing symbols in the error messages pertain to the winsock system library).

OpenGL/glut/stdc++ build errors

I'm using Ubuntu and tried using synaptic to install everything that had the word "GLUT" in it and also SDL and opengl . But still a simple program fails to compile . It shows this :
opengl1.cpp:(.text+0xe): undefined reference to `glClear'
opengl1.cpp:(.text+0x1a): undefined reference to `glBegin'
opengl1.cpp:(.text+0x2e): undefined reference to `glVertex2i'
opengl1.cpp:(.text+0x33): undefined reference to `glEnd'
opengl1.cpp:(.text+0x38): undefined reference to `glFlush'
/tmp/ccnwQeLu.o: In function `MyInit()':
opengl1.cpp:(.text+0x4c): undefined reference to `glGetString'
opengl1.cpp:(.text+0x57): undefined reference to `std::cout'
opengl1.cpp:(.text+0x5c): undefined reference to `std::basic_ostream >& std::operator >(std::basic_ostream >&, unsigned char const*)'
opengl1.cpp:(.text+0x6c): undefined reference to `std::basic_ostream >& std::operator >(std::basic_ostream >&, char const*)'
opengl1.cpp:(.text+0x78): undefined reference to `glGetString'
opengl1.cpp:(.text+0x83): undefined reference to `std::cout'
opengl1.cpp:(.text+0x88): undefined reference to `std::basic_ostream >& std::operator >(std::basic_ostream >&, unsigned char const*)'
opengl1.cpp:(.text+0x98): undefined reference to `std::basic_ostream >& std::operator >(std::basic_ostream >&, char const*)'
opengl1.cpp:(.text+0xc0): undefined reference to `glClearColor'
opengl1.cpp:(.text+0xdf): undefined reference to `glColor3f'
opengl1.cpp:(.text+0xec): undefined reference to `glPointSize'
opengl1.cpp:(.text+0xf8): undefined reference to `glMatrixMode'
opengl1.cpp:(.text+0xfd): undefined reference to `glLoadIdentity'
opengl1.cpp:(.text+0x12d): undefined reference to `gluOrtho2D'
/tmp/ccnwQeLu.o: In function `main':
opengl1.cpp:(.text+0x14a): undefined reference to `glutInit'
opengl1.cpp:(.text+0x156): undefined reference to `glutInitDisplayMode'
opengl1.cpp:(.text+0x16d): undefined reference to `glutInitWindowSize'
opengl1.cpp:(.text+0x181): undefined reference to `glutInitWindowPosition'
opengl1.cpp:(.text+0x18d): undefined reference to `glutCreateWindow'
opengl1.cpp:(.text+0x19e): undefined reference to `glutDisplayFunc'
opengl1.cpp:(.text+0x1a3): undefined reference to `glutMainLoop'
/tmp/ccnwQeLu.o: In function `__static_initialization_and_destruction_0(int, int)':
opengl1.cpp:(.text+0x1cb): undefined reference to `std::ios_base::Init::Init()'
opengl1.cpp:(.text+0x1d0): undefined reference to `std::ios_base::Init::~Init()'
/tmp/ccnwQeLu.o:(.eh_frame+0x12): undefined reference to `__gxx_personality_v0'
collect2: ld returned 1 exit status
If I use g++ instead of gcc I get this:
vim opebgl1.cpp
g++ opengl1.cpp -o opengl1 -lGL -lstdc++ -lc -lm
and then get this :
/tmp/ccCJBuIl.o: In function `MyInit()':
opengl1.cpp:(.text+0x12d): undefined reference to `gluOrtho2D'
/tmp/ccCJBuIl.o: In function `main':
opengl1.cpp:(.text+0x14a): undefined reference to `glutInit'
opengl1.cpp:(.text+0x156): undefined reference to `glutInitDisplayMode'
opengl1.cpp:(.text+0x16d): undefined reference to `glutInitWindowSize'
opengl1.cpp:(.text+0x181): undefined reference to `glutInitWindowPosition'
opengl1.cpp:(.text+0x18d): undefined reference to `glutCreateWindow'
opengl1.cpp:(.text+0x19e): undefined reference to `glutDisplayFunc'
opengl1.cpp:(.text+0x1a3): undefined reference to `glutMainLoop'
collect2: ld returned 1 exit status
So what do I really need to start working with opengl in Ubuntu?
Add "-lstdc++ -lGL" to your linker flags.
Or try to compile it like this:
g++ opengl1.cpp -o opengl1 -lGL -lGLU -lc -lm
(edit: added -lGLU, removed -lstdc++)
You should link it with glut and GLU as well:
g++ opengl1.cpp -o opengl1 -lGL -lstdc++ -lc -lm -lglut -lGLU
Files ended with .cpp must be compiled with g++. The rest of the errors are related to the linking process, and they should not happen if you build your application with the command I suggested above. If they do, make sure you have installed libglut and libglu.
Make sure you are using g++ to build your C++ files to avoid the linker errors pertaining to the C++ standard library.
To resolve the GLUT symbols you probably just need to add -lglut to your final build command.
While compiling the code you must mention some parameters according to your includes.
You already used -lGL, -lm etc.
To use gluOrtho2D the parameter to be used is -lGLU
and for other functions that begin with glut use -lglut