I downloaded and built the wxWidgets library on Ubuntu 21.04 using the following flags:
--enable-monolithic
--disable-shared
--enable-cxx11
--enable-stl
--enable-std_containers_compat
--enable-std_iostreams
--enable-std_string
--enable-std_string_conv_in_wxstring
--disable-unsafe_conv_in_wxstring
--enable-utf8
--enable-profile
--disable-vararg_macros
--enable-universal_binary
--enable-intl
--enable-config
--enable-protocols
--enable-ftp
--enable-http
--enable-fileproto
--enable-sockets
--enable-ipv6
--enable-dataobj
--enable-webrequest
--enable-ipc
--enable-baseevtloop
--enable-epollloop
--enable-selectloop
--enable-any
--enable-arcstream
--enable-base64
--enable-backtrace
--enable-catch_segvs
--enable-cmdline
--enable-datetime
--enable-debugreport
--enable-dialupman
--enable-dynlib
--enable-dynamicloader
--enable-exceptions
--enable-ffile
--enable-file
--enable-filehistory
--enable-filesystem
--enable-fontenum
--enable-fontmap
--enable-fs_archive
--enable-fs_inet
--enable-fsvolume
--enable-fswatcher
--enable-geometry
--enable-log
--enable-longlong
--enable-mimetype
--enable-printfposparam
--enable-secretstore
--enable-snglinst
--enable-sound
--enable-stdpaths
--enable-stopwatch
--enable-streams
--enable-sysoptions
--enable-tarstream
--enable-textbuf
--enable-textfile
--enable-timer
--enable-variant
--enable-zipstream
--enable-url
--enable-protocol
--enable-protocol-http
--enable-protocol-ftp
--enable-protocol-file
--enable-threads
--enable-docview
--enable-help
--enable-html
--enable-htmlhelp
--enable-xrc
--enable-aui
--enable-propgrid
--enable-ribbon
--enable-stc
--enable-constraints
--enable-loggui
--enable-logwin
--enable-logdialog
--enable-mdi
--enable-mdidoc
--enable-mediactrl
--enable-richtext
--enable-postscript
--enable-printarch
--enable-svg
--enable-webview
--enable-graphics_ctx
--enable-clipboard
--enable-dnd
--enable-markup
--enable-accel
--enable-actindicator
--enable-addremovectrl
--enable-animatectrl
--enable-bannerwindow
--enable-artstd
--enable-arttango
--enable-bmpbutton
--enable-bmpcombobox
--enable-button
--enable-calendar
--enable-caret
--enable-checkbox
--enable-checklst
--enable-choice
--enable-choicebook
--enable-collpane
--enable-colourpicker
--enable-combobox
--enable-comboctrl
--enable-commandlinkbutton
--enable-dataviewctrl
--enable-datepick
--enable-detect_sm
--enable-dirpicker
--enable-display
--enable-editablebox
--enable-filectrl
--enable-filepicker
--enable-fontpicker
--enable-gauge
--enable-grid
--enable-headerctrl
--enable-hyperlink
--enable-imaglist
--enable-infobar
--enable-listbook
--enable-listbox
--enable-listctrl
--enable-notebook
--enable-notifmsg
--enable-odcombobox
--enable-popupwin
--enable-prefseditor
--enable-privatefonts
--enable-radiobox
--enable-radiobtn
--enable-richmsgdlg
--enable-richtooltip
--enable-rearrangectrl
--enable-sash
--enable-scrollbar
--enable-searchctrl
--enable-slider
--enable-spinbtn
--enable-spinctrl
--enable-splitter
--enable-statbmp
--enable-statbox
--enable-statline
--enable-stattext
--enable-statusbar
--enable-taskbaricon
--enable-tbarnative
--enable-textctrl
--enable-timepick
--enable-tipwindow
--enable-togglebtn
--enable-toolbar
--enable-toolbook
--enable-treebook
--enable-treectrl
--enable-treelist
--enable-commondlg
--enable-aboutdlg
--enable-choicedlg
--enable-coldlg
--enable-creddlg
--enable-filedlg
--enable-finddlg
--enable-fontdlg
--enable-dirdlg
--enable-msgdlg
--enable-numberdlg
--enable-splash
--enable-textdlg
--enable-tipdlg
--enable-progressdlg
--enable-wizarddlg
--enable-menus
--enable-menubar
--enable-miniframe
--enable-tooltips
--enable-splines
--enable-mousewheel
--enable-validators
--enable-busyinfo
--enable-hotkey
--enable-joystick
--enable-metafile
--enable-dragimage
--enable-dctransform
--enable-webviewwebkit
--enable-palette
--enable-image
--enable-gif
--enable-pcx
--enable-tga
--enable-iff
--enable-pnm
--enable-xpm
--enable-ico_cur
--enable-autoidman
I used all these flags because I mainly want to play around with the library and having a static, monolithic library with all the features enabled suits that purpose. At first I faced some issues at configuration with GStreamer which wasn't installed but after I installed it the library compiled just fine. For the sake of completeness, these are the exact steps I followed:
#Current dir -> ~/Programs/C++/wxWidgets-3.1.5
mkdir build-gtk
cd build-gtk
../configure #all the above flags
make
sudo checkinstall
and finally I installed the library through the generated .deb file.
I then proceeded to build the sample files with the provided make files. All but two compiled, mediaplayer and splash directories. Again, the exact procedure I followed was:
cd samples
make
The error I got for mediaplayer is:
/usr/bin/ld: ~/Programs/C++/wxWidgets-3.1.5/build-gtk/lib/libwx_gtk3u-3.1.a(monolib_unix_mediactrl.o): in function `draw':
mediactrl.cpp:(.text+0x195): undefined reference to `gst_video_overlay_expose'
/usr/bin/ld: ~/Programs/C++/wxWidgets-3.1.5/build-gtk/lib/libwx_gtk3u-3.1.a(monolib_unix_mediactrl.o): in function `wxGStreamerMediaBackend::SetPosition(wxLongLongNative)':
mediactrl.cpp:(.text+0x200): undefined reference to `gst_element_seek'
/usr/bin/ld: ~/Programs/C++/wxWidgets-3.1.5/build-gtk/lib/libwx_gtk3u-3.1.a(monolib_unix_mediactrl.o): in function `wxGStreamerMediaBackend::GetDuration()':
mediactrl.cpp:(.text+0x24f): undefined reference to `gst_element_query_duration'
/usr/bin/ld: ~/Programs/C++/wxWidgets-3.1.5/build-gtk/lib/libwx_gtk3u-3.1.a(monolib_unix_mediactrl.o): in function `wxGStreamerMediaBackend::GetDownloadTotal()':
mediactrl.cpp:(.text+0x2cf): undefined reference to `gst_element_query_duration'
/usr/bin/ld: ~/Programs/C++/wxWidgets-3.1.5/build-gtk/lib/libwx_gtk3u-3.1.a(monolib_unix_mediactrl.o): in function `wxGStreamerMediaBackend::GetPosition()':
mediactrl.cpp:(.text+0x545): undefined reference to `gst_element_query_position'
/usr/bin/ld: ~/Programs/C++/wxWidgets-3.1.5/build-gtk/lib/libwx_gtk3u-3.1.a(monolib_unix_mediactrl.o): in function `gtk_window_realize_callback':
mediactrl.cpp:(.text+0x615): undefined reference to `gst_video_overlay_set_window_handle'
/usr/bin/ld: ~/Programs/C++/wxWidgets-3.1.5/build-gtk/lib/libwx_gtk3u-3.1.a(monolib_unix_mediactrl.o): in function `wxGStreamerMediaBackend::~wxGStreamerMediaBackend()':
mediactrl.cpp:(.text+0x6e6): undefined reference to `gst_object_get_type'
/usr/bin/ld: mediactrl.cpp:(.text+0x75a): undefined reference to `gst_element_set_state'
/usr/bin/ld: mediactrl.cpp:(.text+0x75f): undefined reference to `gst_object_get_type'
/usr/bin/ld: mediactrl.cpp:(.text+0x773): undefined reference to `gst_object_unref'
/usr/bin/ld: ~/Programs/C++/wxWidgets-3.1.5/build-gtk/lib/libwx_gtk3u-3.1.a(monolib_unix_mediactrl.o): in function `wxGStreamerMediaBackend::SetupXOverlay()':
mediactrl.cpp:(.text+0x918): undefined reference to `gst_video_overlay_set_window_handle'
/usr/bin/ld: ~/Programs/C++/wxWidgets-3.1.5/build-gtk/lib/libwx_gtk3u-3.1.a(monolib_unix_mediactrl.o): in function `wxGStreamerMediaBackend::TryAudioSink(_GstElement*)':
mediactrl.cpp:(.text+0xac8): undefined reference to `gst_element_get_type'
/usr/bin/ld: ~/Programs/C++/wxWidgets-3.1.5/build-gtk/lib/libwx_gtk3u-3.1.a(monolib_unix_mediactrl.o): in function `wxGStreamerMediaBackend::TryVideoSink(_GstElement*)':
mediactrl.cpp:(.text+0xb5e): undefined reference to `gst_bin_get_type'
/usr/bin/ld: mediactrl.cpp:(.text+0xb89): undefined reference to `gst_video_overlay_get_type'
/usr/bin/ld: mediactrl.cpp:(.text+0xbaf): undefined reference to `gst_bin_get_type'
/usr/bin/ld: mediactrl.cpp:(.text+0xbd1): undefined reference to `gst_video_overlay_get_type'
/usr/bin/ld: mediactrl.cpp:(.text+0xbd9): undefined reference to `gst_bin_get_type'
/usr/bin/ld: mediactrl.cpp:(.text+0xbef): undefined reference to `gst_bin_get_by_interface'
/usr/bin/ld: mediactrl.cpp:(.text+0xbfb): undefined reference to `gst_video_overlay_get_type'
/usr/bin/ld: mediactrl.cpp:(.text+0xc2a): undefined reference to `gst_element_set_state'
/usr/bin/ld: mediactrl.cpp:(.text+0xc50): undefined reference to `gst_video_overlay_get_type'
/usr/bin/ld: mediactrl.cpp:(.text+0xc61): undefined reference to `gst_video_overlay_get_type'
/usr/bin/ld: ~/Programs/C++/wxWidgets-3.1.5/build-gtk/lib/libwx_gtk3u-3.1.a(monolib_unix_mediactrl.o): in function `wxGStreamerMediaBackend::CreateControl(wxControl*, wxWindow*, int, wxPoint const&, wxSize const&, long, wxValidator const&, wxString const&)':
mediactrl.cpp:(.text+0x100c): undefined reference to `gst_init_check'
/usr/bin/ld: mediactrl.cpp:(.text+0x122a): undefined reference to `gst_element_factory_make'
/usr/bin/ld: mediactrl.cpp:(.text+0x1236): undefined reference to `gst_element_get_type'
/usr/bin/ld: mediactrl.cpp:(.text+0x190c): undefined reference to `gst_element_get_bus'
/usr/bin/ld: mediactrl.cpp:(.text+0x191e): undefined reference to `gst_bus_add_watch'
/usr/bin/ld: mediactrl.cpp:(.text+0x1927): undefined reference to `gst_element_get_bus'
/usr/bin/ld: mediactrl.cpp:(.text+0x193b): undefined reference to `gst_bus_set_sync_handler'
/usr/bin/ld: mediactrl.cpp:(.text+0x194e): undefined reference to `gst_element_factory_make'
/usr/bin/ld: mediactrl.cpp:(.text+0x1977): undefined reference to `gst_element_factory_make'
/usr/bin/ld: mediactrl.cpp:(.text+0x19a0): undefined reference to `gst_element_factory_make'
/usr/bin/ld: mediactrl.cpp:(.text+0x1b4f): undefined reference to `gst_element_factory_make'
/usr/bin/ld: mediactrl.cpp:(.text+0x1b7f): undefined reference to `gst_element_factory_make'
/usr/bin/ld: ~/Programs/C++/wxWidgets-3.1.5/build-gtk/lib/libwx_gtk3u-3.1.a(monolib_unix_mediactrl.o):mediactrl.cpp:(.text+0x1ba8): more undefined references to `gst_element_factory_make' follow
/usr/bin/ld: ~/Programs/C++/wxWidgets-3.1.5/build-gtk/lib/libwx_gtk3u-3.1.a(monolib_unix_mediactrl.o): in function `wxGStreamerMediaBackend::CreateControl(wxControl*, wxWindow*, int, wxPoint const&, wxSize const&, long, wxValidator const&, wxString const&)':
mediactrl.cpp:(.text+0x1d2b): undefined reference to `gst_element_get_static_pad'
/usr/bin/ld: mediactrl.cpp:(.text+0x1d5c): undefined reference to `gst_object_unref'
/usr/bin/ld: ~/Programs/C++/wxWidgets-3.1.5/build-gtk/lib/libwx_gtk3u-3.1.a(monolib_unix_mediactrl.o): in function `wxGStreamerMediaBackend::Play()':
mediactrl.cpp:(.text+0x30d1): undefined reference to `gst_element_set_state'
/usr/bin/ld: ~/Programs/C++/wxWidgets-3.1.5/build-gtk/lib/libwx_gtk3u-3.1.a(monolib_unix_mediactrl.o): in function `wxGStreamerMediaBackend::Pause()':
mediactrl.cpp:(.text+0x312c): undefined reference to `gst_element_set_state'
/usr/bin/ld: ~/Programs/C++/wxWidgets-3.1.5/build-gtk/lib/libwx_gtk3u-3.1.a(monolib_unix_mediactrl.o): in function `wxGStreamerMediaBackend::QueryVideoSizeFromPad(_GstPad*)':
mediactrl.cpp:(.text+0x3f44): undefined reference to `gst_pad_get_current_caps'
/usr/bin/ld: mediactrl.cpp:(.text+0x3f5a): undefined reference to `gst_caps_get_structure'
/usr/bin/ld: mediactrl.cpp:(.text+0x3f79): undefined reference to `gst_structure_get_int'
/usr/bin/ld: mediactrl.cpp:(.text+0x3f8c): undefined reference to `gst_structure_get_int'
/usr/bin/ld: mediactrl.cpp:(.text+0x3fa2): undefined reference to `gst_structure_get_value'
/usr/bin/ld: mediactrl.cpp:(.text+0x40be): undefined reference to `gst_mini_object_unref'
/usr/bin/ld: ~/Programs/C++/wxWidgets-3.1.5/build-gtk/lib/libwx_gtk3u-3.1.a(monolib_unix_mediactrl.o): in function `gst_bus_async_callback':
mediactrl.cpp:(.text+0x5fe7): undefined reference to `gst_message_parse_state_changed'
/usr/bin/ld: mediactrl.cpp:(.text+0x6014): undefined reference to `gst_message_parse_error'
/usr/bin/ld: ~/Programs/C++/wxWidgets-3.1.5/build-gtk/lib/libwx_gtk3u-3.1.a(monolib_unix_mediactrl.o): in function `gst_bus_sync_callback':
mediactrl.cpp:(.text+0x607a): undefined reference to `gst_is_video_overlay_prepare_window_handle_message'
/usr/bin/ld: ~/Programs/C++/wxWidgets-3.1.5/build-gtk/lib/libwx_gtk3u-3.1.a(monolib_unix_mediactrl.o): in function `wxGStreamerMediaBackend::SyncStateChange(_GstElement*, GstState, long)':
mediactrl.cpp:(.text+0x6497): undefined reference to `gst_element_get_bus'
/usr/bin/ld: mediactrl.cpp:(.text+0x64b0): undefined reference to `gst_bus_have_pending'
/usr/bin/ld: mediactrl.cpp:(.text+0x64f4): undefined reference to `gst_bus_pop'
/usr/bin/ld: mediactrl.cpp:(.text+0x6505): undefined reference to `gst_mini_object_unref'
/usr/bin/ld: mediactrl.cpp:(.text+0x656b): undefined reference to `gst_mini_object_unref'
/usr/bin/ld: mediactrl.cpp:(.text+0x65b9): undefined reference to `gst_message_parse_state_changed'
/usr/bin/ld: mediactrl.cpp:(.text+0x65d3): undefined reference to `gst_mini_object_unref'
/usr/bin/ld: mediactrl.cpp:(.text+0x65fa): undefined reference to `gst_message_parse_error'
/usr/bin/ld: mediactrl.cpp:(.text+0x661c): undefined reference to `gst_mini_object_unref'
/usr/bin/ld: ~/Programs/C++/wxWidgets-3.1.5/build-gtk/lib/libwx_gtk3u-3.1.a(monolib_unix_mediactrl.o): in function `wxGStreamerMediaEventHandler::OnMediaFinish(wxMediaEvent&)':
mediactrl.cpp:(.text+0x69d1): undefined reference to `gst_element_set_state'
/usr/bin/ld: mediactrl.cpp:(.text+0x69fa): undefined reference to `gst_element_set_state'
/usr/bin/ld: ~/Programs/C++/wxWidgets-3.1.5/build-gtk/lib/libwx_gtk3u-3.1.a(monolib_unix_mediactrl.o): in function `wxGStreamerMediaBackend::DoLoad(wxString const&)':
mediactrl.cpp:(.text+0x6ad6): undefined reference to `gst_element_set_state'
/usr/bin/ld: mediactrl.cpp:(.text+0x703a): undefined reference to `gst_element_set_state'
/usr/bin/ld: mediactrl.cpp:(.text+0x7046): undefined reference to `gst_uri_protocol_is_valid'
/usr/bin/ld: mediactrl.cpp:(.text+0x70c0): undefined reference to `gst_uri_is_valid'
/usr/bin/ld: mediactrl.cpp:(.text+0x71f0): undefined reference to `gst_element_set_state'
/usr/bin/ld: ~/Programs/C++/wxWidgets-3.1.5/build-gtk/lib/libwx_gtk3u-3.1.a(monolib_unix_mediactrl.o): in function `wxGStreamerMediaBackend::Stop()':
mediactrl.cpp:(.text+0x7759): undefined reference to `gst_element_set_state'
collect2: error: ld returned 1 exit status
make tried to compile the the sample running g++ with the following flags (quoting them in separate lines for readability):
g++
-std=gnu++11
-o mediaplayer mediaplayer_mediaplayer.o
-L~/Programs/C++/wxWidgets-3.1.5/build-gtk/lib
-pthread
-pg
-lgstvideo-1.0
-lgstbase-1.0
-lgstreamer-1.0
-lgobject-2.0
-lglib-2.0
-lwx_gtk3u-3.1
-lwxscintilla-3.1
-lwxregexu-3.1
-pthread
-lz
-ldl
-lcurl
-llzma
-lm
-lexpat
-lgtk-3
-lgdk-3
-lpangocairo-1.0
-lpango-1.0
-lharfbuzz
-latk-1.0
-lcairo-gobject
-lcairo
-lgdk_pixbuf-2.0
-lgio-2.0
-lgobject-2.0
-lgthread-2.0
-pthread
-lglib-2.0
-lX11
-lSM
-lgtk-3
-lgdk-3
-lpangocairo-1.0
-lpango-1.0
-lharfbuzz
-latk-1.0
-lcairo-gobject
-lcairo
-lgdk_pixbuf-2.0
-lgio-2.0
-lgobject-2.0
-lglib-2.0
-lnotify
-lgdk_pixbuf-2.0
-lgio-2.0
-lgobject-2.0
-lglib-2.0
-lXtst
-lpangoft2-1.0
-lpango-1.0
-lgobject-2.0
-lglib-2.0
-lharfbuzz
-lfontconfig
-lfreetype
-lpng
-lz
-ljpeg
-ltiff
-llzma
-ljbig
-lz
-ldl
-lcurl
-llzma
-lm
I've been trying two days now to solve this but I can't figured it out. I've tried installing all the possible GStreamer packages, copying the GStreamer libraries and header files to a bunch of different location, I tried --reinstall and other things but at this point I haven't managed to get anywhere. Does anyone know what am I missing here? How can I compile these sample files?
Edit:
As #VZ. pointed out I should make more clear that:
The make files were autogenerated by building wxWidgets library.
There was a makefile in the build-gtk/samples directory which would compile in batch all examples.
In each example (e.g. build-gtk/samples/mediaplayer) there was a makefile generated by a bakefile - the first lines are a block comment saying:
# =========================================================================
# This makefile was generated by
# Bakefile 0.2.12 ([http://www.bakefile.org][1])
# Do not modify, all changes will be overwritten!
# =========================================================================
I ran make in build-gtk/samples, which compiled all examples except build-gtk/samples/mediaplayer and build-gtk/samples/splash.
Following #VZ.'s answer I also tried to manually compile build-gtk/samples/mediaplayer using g++ and changing the order of the libraries I got the following error:
/usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/10/../../../x86_64-linux-gnu/libgstvideo-1.0.so: undefined reference to `gst_event_parse_instant_rate_change'
/usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/10/../../../x86_64-linux-gnu/libgstvideo-1.0.so: undefined reference to `gst_aggregator_simple_get_next_time'
/usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/10/../../../x86_64-linux-gnu/libgstvideo-1.0.so: undefined reference to `gst_base_sink_set_processing_deadline'
/usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/10/../../../x86_64-linux-gnu/libgstvideo-1.0.so: undefined reference to `gst_mini_object_add_parent'
/usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/10/../../../x86_64-linux-gnu/libgstvideo-1.0.so: undefined reference to `gst_mini_object_remove_parent'
/usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/10/../../../x86_64-linux-gnu/libgstvideo-1.0.so: undefined reference to `gst_aggregator_selected_samples'
collect2: error: ld returned 1 exit status
Edit 2:
I fixed the aforementioned error by running the following:
sudo rm /usr/local/lib/libgstbase-1.0.so*
sudo rm /usr/local/lib/libgstreamer-1.0.*
effectively removing any gstreamer libraries under /usr/local/lib that seemed to be conflicting with some other gstreamer libraries elsewhere in the system.
There is a problem with the order of the libraries in the link command you show, gstreamer libraries must come after -lwx_gtk3u-3.1 and not before it as they do, when using static libraries.
It's not clear to me where does this command actually come from, normally you should run make inside build-gtk/samples/mediaplayer directory, is this really what you're doing? I.e. how exactly do you the provided makefiles and which ones are you using?
This looks like a bug in static monolithic build when using media library and should be fixed in wxWidgets itself. I don't know about the new errors, i.e. the missing gst_event_parse_instant_rate_change and other symbols, I don't have anything like this on my system, so I suspect this might be due to a mix of gstreamer libraries on your system due to your previous attempts to circumvent the problem.
P.S. Avoid using all these --enable-xxx options, they're all on by default anyhow (and those that are off are usually off for a good reason).
Related
There is a error when compiling opencv program program simple includes #include <opencv2/core.hpp>
I compiled it with this command
g++ test.cpp -o app `pkg-config --cflags --libs opencv`
compiling opencv in c++
This is full error
gcc -I/usr/local/lib test.cpp
test.cpp:1:10: fatal error: opencv2/core.hpp: No such file or directory
1 | #include <opencv2/core.hpp>
I compiled and install the opencv by looking at this page https://docs.opencv.org/2.4/doc/tutorials/introduction/linux_install/linux_install.html#building-opencv-from-source-using-cmake-using-the-command-line
The code is from https://docs.opencv.org/4.x/d3/d50/group__imgproc__colormap.html
Also my opencv so files are located at /usr/local/lib
Error also says
Perhaps you should add the directory containing `opencv.pc'
to the PKG_CONFIG_PATH environment variable
but I searched /usr directory there is no opencv.pc file
Update
Compiling program after updating my compile command This error throws
$g++ -I/usr/local/include/opencv4/ test.cpp
/usr/bin/ld: /tmp/ccuJvWgF.o: in function `main':
test.cpp:(.text+0xb4): undefined reference to `cv::imread(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int)'
/usr/bin/ld: test.cpp:(.text+0xde): undefined reference to `cv::Mat::empty() const'
/usr/bin/ld: test.cpp:(.text+0x154): undefined reference to `cv::Mat::Mat()'
/usr/bin/ld: test.cpp:(.text+0x1a1): undefined reference to `cv::applyColorMap(cv::_InputArray const&, cv::_OutputArray const&, int)'
/usr/bin/ld: test.cpp:(.text+0x21d): undefined reference to `cv::imshow(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, cv::_InputArray const&)'
/usr/bin/ld: test.cpp:(.text+0x254): undefined reference to `cv::waitKey(int)'
/usr/bin/ld: test.cpp:(.text+0x265): undefined reference to `cv::Mat::~Mat()'
/usr/bin/ld: test.cpp:(.text+0x274): undefined reference to `cv::Mat::~Mat()'
/usr/bin/ld: test.cpp:(.text+0x33d): undefined reference to `cv::Mat::~Mat()'
/usr/bin/ld: test.cpp:(.text+0x355): undefined reference to `cv::Mat::~Mat()'
collect2: error: ld returned 1 exit status
$
Update 2
when now compiling
g++ -L/usr/local/lib/libopencv_core.so -I/usr/local/include/opencv4/ test.cpp
it throws this error. There are many opencv so files in /usr/local/lib do I need to include specific opencv so files to compile the code in the link
in function `main':
test.cpp:(.text+0xb4): undefined reference to `cv::imread(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int)'
/usr/bin/ld: test.cpp:(.text+0xde): undefined reference to `cv::Mat::empty() const'
/usr/bin/ld: test.cpp:(.text+0x154): undefined reference to `cv::Mat::Mat()'
/usr/bin/ld: test.cpp:(.text+0x1a1): undefined reference to `cv::applyColorMap(cv::_InputArray const&, cv::_OutputArray const&, int)'
/usr/bin/ld: test.cpp:(.text+0x21d): undefined reference to `cv::imshow(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, cv::_InputArray const&)'
/usr/bin/ld: test.cpp:(.text+0x254): undefined reference to `cv::waitKey(int)'
/usr/bin/ld: test.cpp:(.text+0x265): undefined reference to `cv::Mat::~Mat()'
/usr/bin/ld: test.cpp:(.text+0x274): undefined reference to `cv::Mat::~Mat()'
/usr/bin/ld: test.cpp:(.text+0x33d): undefined reference to `cv::Mat::~Mat()'
/usr/bin/ld: test.cpp:(.text+0x355): undefined reference to `cv::Mat::~Mat()'
collect2: error: ld returned 1 exit sta
With the -L option you should specify the library search path.
Then with -l options you specify the library names you'd like to link against.
So in your case I'd expect to see -L/usr/local/lib -lopencv_core. Note that the -l name has the lib prefix and file extension omitted. (You may need more OpenCV libraries.)
Seeing your struggles, I think it would be good to read a general tutorial about compiling and linking C/C++ programs (on your platform).
I had a similar problem when I moved some code from OpenCV2 to OpenCV4, it appears you are using some OpenCV4 as well. My fix was to not include opencv2/ but to include opencv4/opencv2/. Not exactly sure what about that made it work, I did that way too long ago, but it worked since.
I am trying to integrate librealsense C++ CLion Project on Ubuntu 20.04.
Compiling the Librealsense separately in the terminal works just as expected.
the Project looks like this:
RS_Pipeline
.
├── build
├── main.cpp
├── CMakeLists.txt
└── librealsense // the integrated lib
├── CMakeLists.txt
├── third-party // libs like GLFW and GLAD which are use in the examples
├── examples //
| ├── example.hpp // with class to generate OpenGL Window
└── ...
The CMakeLists.txt in the base Folder looks rather simple:
cmake_minimum_required(VERSION 3.2)
project(RS_Pipeline LANGUAGES CXX C)
set(CMAKE_CXX_STANDARD 11)
set(OpenGL_GL_PREFERENCE LEGACY)
add_executable(RS_Pipeline main.cpp librealsense/examples/example.hpp)
add_subdirectory(librealsense)
target_link_libraries(${PROJECT_NAME} realsense2)
As soon as i try to include the submodul into my CLion Project i get a ton of: main.cpp:(.text+0x23c): undefined reference to glViewport error messages and building my main.cpp in the base dir fails.
somehow the #include <librealsense2/rs.hpp> #include "librealsense/examples/example.hpp"
works fine and even the intellisense finds all the functions.
PLUS: the included examples within the librealsense Library also compile without any problem. (They use exactly the same #include "librealsense/examples/example.hpp".
It looks like, that CLion just dose not link find the right openGL in my own main.cpp resp. if i include it from example.hpp.
====================[ Build | RS_Pipeline | Release ]===========================
/snap/clion/175/bin/cmake/linux/bin/cmake --build /home/lukas/Development/Cpp/RS_Pipeline/cmake-build-release --target RS_Pipeline
[0/1] Re-running CMake...
-- Checking internet connection...
-- Internet connection identified
-- Info: REALSENSE_VERSION_STRING=2.50.0
-- Setting Unix configurations
-- Building libcurl enabled
-- using RS2_USE_V4L2_BACKEND
-- Could NOT find apriltag (missing: APRILTAG_INC APRILTAG_LIB)
-- Unable to find apriltag library, skipping pose-apriltag example
-- Check for updates capability added to realsense-viewer
-- Check for updates capability added to realsense-depth-quality
-- Building with TM2
-- Fetching recommended firmwares:
-- D4XX_FW_VERSION: 5.13.0.50
-- SR3XX_FW_VERSION: 3.26.1.0
-- T26X_FW_VERSION: 0.2.0.951
-- L51X_FW_VERSION: 1.5.8.1
-- L53X_FW_VERSION: 3.5.5.1
-- https://librealsense.intel.com/Releases/RS4xx/FW/D4XX_FW_Image-5.13.0.50.bin
-- Download firmware 0;"returning early; file already exists with expected SHA1 hash" for D4XX_FW_Image-5.13.0.50.bin
-- https://librealsense.intel.com/Releases/SR300/FW/SR3XX_FW_Image-3.26.1.0.bin
-- Download firmware 0;"returning early; file already exists with expected SHA1 hash" for SR3XX_FW_Image-3.26.1.0.bin
-- https://librealsense.intel.com/Releases/TM2/FW/target/0.2.0.951/target-0.2.0.951.mvcmd
-- Download firmware 0;"returning early; file already exists with expected SHA1 hash" for target-0.2.0.951.mvcmd
-- https://librealsense.intel.com/Releases/L5xx/FW/L51X_FW_Image-1.5.8.1.bin
-- Download firmware 0;"returning early; file already exists with expected SHA1 hash" for L51X_FW_Image-1.5.8.1.bin
-- https://librealsense.intel.com/Releases/L5xx/FW/L53X_FW_Image-3.5.5.1.bin
-- Download firmware 0;"returning early; file already exists with expected SHA1 hash" for L53X_FW_Image-3.5.5.1.bin
-- Configuring done
-- Generating done
-- Build files have been written to: /home/lukas/Development/Cpp/RS_Pipeline/cmake-build-release
[1/1] Linking CXX executable RS_Pipeline
FAILED: RS_Pipeline
: && /usr/bin/c++ -O3 -DNDEBUG -rdynamic CMakeFiles/RS_Pipeline.dir/main.cpp.o -o RS_Pipeline -Wl,-rpath,/home/lukas/Development/Cpp/RS_Pipeline/cmake-build-release/librealsense librealsense/librealsense2.so.2.50.0 -lglfw && :
/usr/bin/ld: CMakeFiles/RS_Pipeline.dir/main.cpp.o: in function `set_viewport(rect const&)':
main.cpp:(.text+0x23c): undefined reference to `glViewport'
/usr/bin/ld: main.cpp:(.text+0x241): undefined reference to `glLoadIdentity'
/usr/bin/ld: main.cpp:(.text+0x24b): undefined reference to `glMatrixMode'
/usr/bin/ld: CMakeFiles/RS_Pipeline.dir/main.cpp.o: in function `draw_pointcloud(float, float, glfw_state&, rs2::points&)':
main.cpp:(.text+0x2bb): undefined reference to `glLoadIdentity'
/usr/bin/ld: main.cpp:(.text+0x2c5): undefined reference to `glPushAttrib'
/usr/bin/ld: main.cpp:(.text+0x2e0): undefined reference to `glClearColor'
/usr/bin/ld: main.cpp:(.text+0x2ea): undefined reference to `glClear'
/usr/bin/ld: main.cpp:(.text+0x2f4): undefined reference to `glMatrixMode'
/usr/bin/ld: main.cpp:(.text+0x2f9): undefined reference to `glPushMatrix'
/usr/bin/ld: main.cpp:(.text+0x32a): undefined reference to `gluPerspective'
/usr/bin/ld: main.cpp:(.text+0x334): undefined reference to `glMatrixMode'
/usr/bin/ld: main.cpp:(.text+0x339): undefined reference to `glPushMatrix'
/usr/bin/ld: main.cpp:(.text+0x36c): undefined reference to `gluLookAt'
/usr/bin/ld: main.cpp:(.text+0x394): undefined reference to `glTranslatef'
/usr/bin/ld: main.cpp:(.text+0x3b2): undefined reference to `glRotated'
/usr/bin/ld: main.cpp:(.text+0x3cf): undefined reference to `glRotated'
/usr/bin/ld: main.cpp:(.text+0x3e3): undefined reference to `glTranslatef'
/usr/bin/ld: main.cpp:(.text+0x3f6): undefined reference to `glPointSize'
/usr/bin/ld: main.cpp:(.text+0x400): undefined reference to `glEnable'
/usr/bin/ld: main.cpp:(.text+0x40a): undefined reference to `glEnable'
/usr/bin/ld: main.cpp:(.text+0x417): undefined reference to `glBindTexture'
/usr/bin/ld: main.cpp:(.text+0x437): undefined reference to `glTexParameterfv'
/usr/bin/ld: main.cpp:(.text+0x44b): undefined reference to `glTexParameteri'
/usr/bin/ld: main.cpp:(.text+0x45f): undefined reference to `glTexParameteri'
/usr/bin/ld: main.cpp:(.text+0x466): undefined reference to `glBegin'
/usr/bin/ld: main.cpp:(.text+0x516): undefined reference to `glEnd'
/usr/bin/ld: main.cpp:(.text+0x51b): undefined reference to `glPopMatrix'
/usr/bin/ld: main.cpp:(.text+0x525): undefined reference to `glMatrixMode'
/usr/bin/ld: main.cpp:(.text+0x52a): undefined reference to `glPopMatrix'
/usr/bin/ld: main.cpp:(.text+0x52f): undefined reference to `glPopAttrib'
/usr/bin/ld: main.cpp:(.text+0x558): undefined reference to `glVertex3fv'
/usr/bin/ld: main.cpp:(.text+0x566): undefined reference to `glTexCoord2fv'
/usr/bin/ld: CMakeFiles/RS_Pipeline.dir/main.cpp.o: in function `draw_pointcloud_wrt_world(float, float, glfw_state&, rs2::points&, rs2_pose&, float*, std::vector >&)':
main.cpp:(.text+0x98b): undefined reference to `glLoadIdentity'
/usr/bin/ld: main.cpp:(.text+0x995): undefined reference to `glPushAttrib'
/usr/bin/ld: main.cpp:(.text+0x9b0): undefined reference to `glClearColor'
/usr/bin/ld: main.cpp:(.text+0x9ba): undefined reference to `glClear'
/usr/bin/ld: main.cpp:(.text+0x9c4): undefined reference to `glMatrixMode'
/usr/bin/ld: main.cpp:(.text+0x9c9): undefined reference to `glPushMatrix'
/usr/bin/ld: main.cpp:(.text+0x9fa): undefined reference to `gluPerspective'
/usr/bin/ld: main.cpp:(.text+0xa04): undefined reference to `glMatrixMode'
/usr/bin/ld: main.cpp:(.text+0xa09): undefined reference to `glPushMatrix'
/usr/bin/ld: main.cpp:(.text+0xa2f): undefined reference to `glTranslatef'
/usr/bin/ld: main.cpp:(.text+0xa4a): undefined reference to `glRotated'
/usr/bin/ld: main.cpp:(.text+0xa65): undefined reference to `glRotated'
/usr/bin/ld: main.cpp:(.text+0xa79): undefined reference to `glTranslatef'
/usr/bin/ld: main.cpp:(.text+0xa83): undefined reference to `glEnable'
/usr/bin/ld: main.cpp:(.text+0xa90): undefined reference to `glLineWidth'
/usr/bin/ld: main.cpp:(.text+0xa9a): undefined reference to `glBegin'
/usr/bin/ld: main.cpp:(.text+0xac4): undefined reference to `glColor3f'
/usr/bin/ld: main.cpp:(.text+0xad8): undefined reference to `glVertex3f'
/usr/bin/ld: main.cpp:(.text+0xae2): undefined reference to `glEnd'
/usr/bin/ld: main.cpp:(.text+0xaef): undefined reference to `glLineWidth'
/usr/bin/ld: main.cpp:(.text+0xb02): undefined reference to `glColor3f'
/usr/bin/ld: main.cpp:(.text+0xb2f): undefined reference to `glMultMatrixf'
/usr/bin/ld: main.cpp:(.text+0xb37): undefined reference to `glMultMatrixf'
/usr/bin/ld: main.cpp:(.text+0xb4a): undefined reference to `glPointSize'
/usr/bin/ld: main.cpp:(.text+0xb54): undefined reference to `glEnable'
/usr/bin/ld: main.cpp:(.text+0xb5e): undefined reference to `glEnable'
/usr/bin/ld: main.cpp:(.text+0xb71): undefined reference to `glBindTexture'
/usr/bin/ld: main.cpp:(.text+0xb91): undefined reference to `glTexParameterfv'
/usr/bin/ld: main.cpp:(.text+0xba5): undefined reference to `glTexParameteri'
/usr/bin/ld: main.cpp:(.text+0xbb9): undefined reference to `glTexParameteri'
/usr/bin/ld: main.cpp:(.text+0xbc0): undefined reference to `glBegin'
/usr/bin/ld: main.cpp:(.text+0xc76): undefined reference to `glEnd'
/usr/bin/ld: main.cpp:(.text+0xc7b): undefined reference to `glPopMatrix'
/usr/bin/ld: main.cpp:(.text+0xc85): undefined reference to `glMatrixMode'
/usr/bin/ld: main.cpp:(.text+0xc8a): undefined reference to `glPopMatrix'
/usr/bin/ld: main.cpp:(.text+0xc8f): undefined reference to `glPopAttrib'
/usr/bin/ld: main.cpp:(.text+0xcc0): undefined reference to `glVertex3fv'
/usr/bin/ld: main.cpp:(.text+0xcce): undefined reference to `glTexCoord2fv'
/usr/bin/ld: CMakeFiles/RS_Pipeline.dir/main.cpp.o: in function `set_viewport(rect const&)':
main.cpp:(.text+0x27b): undefined reference to `glOrtho'
collect2: error: ld returned 1 exit status
ninja: build stopped: subcommand failed.
The examples all include this file, while you don't:
find_package(OpenGL REQUIRED)
set(DEPENDENCIES realsense2 glfw ${OPENGL_LIBRARIES})
which makes the realsense2 library depend on GLFW and your OpenGL stack.
Add the following to your CMakeLists.txt:
find_package(OpenGL REQUIRED)
target_link_libraries(${PROJECT_NAME} glfw OpenGL::GL )
#Botje Thanks a lot, that was fast! now it is working with the following CMakeLists:
cmake_minimum_required(VERSION 3.2)
project(RS_Pipeline LANGUAGES CXX C)
set(CMAKE_CXX_STANDARD 11)
set(OpenGL_GL_PREFERENCE LEGACY)
find_package(OpenGL REQUIRED)
add_executable(RS_Pipeline main.cpp librealsense/examples/example.hpp)
add_subdirectory(librealsense)
target_link_libraries(${PROJECT_NAME}
realsense2
glfw OpenGL::GL
glfw OpenGL::GLU
)
looks like this topic can be closed already.
I have installed Proj 6.3.1 and I tried to run a Proj example from https://proj.org/development/quickstart.html. I implemented it with CLion on Ubuntu 20.04. And I got many undefined reference errors as follows,
cd "/path_to_the_file/" && g++ transformation.cpp -o transformation && "/path_to_the_file/"transformation
/usr/bin/ld: /tmp/cckO2X58.o: in function `main':
transformation.cpp:(.text+0x1f): undefined reference to `proj_context_create'
/usr/bin/ld: transformation.cpp:(.text+0x42): undefined reference to `proj_create_crs_to_crs'
/usr/bin/ld: transformation.cpp:(.text+0x8a): undefined reference to `proj_normalize_for_visualization'
/usr/bin/ld: transformation.cpp:(.text+0xcb): undefined reference to `proj_destroy'
/usr/bin/ld: transformation.cpp:(.text+0x102): undefined reference to `proj_coord'
/usr/bin/ld: transformation.cpp:(.text+0x14f): undefined reference to `proj_trans'
/usr/bin/ld: transformation.cpp:(.text+0x1c3): undefined reference to `proj_trans'
/usr/bin/ld: transformation.cpp:(.text+0x21c): undefined reference to `proj_destroy'
/usr/bin/ld: transformation.cpp:(.text+0x228): undefined reference to `proj_context_destroy'
collect2: error: ld returned 1 exit status
This problem is similar to https://gis.stackexchange.com/questions/370771/unable-to-run-proj-c-example, but I can't find the solutions accordingly. The <proj.h> header is in my usr/include folder and Clion can detect it automatically. Could anyone help?
I'm trying out this library:
https://github.com/dacap/clip
I've git-cloned it, then built it using the following:
cmake .
make
This produces a library called libclip.a.
Now, I've taken the sample Hello World code, which is this:
#include "clip/clip.h"
int main() {
clip::set_text("Hello World");
}
Given that the above is in a file called cliptest2.cpp, I compile it as follows:
g++ -lclip cliptest2.cpp -o cliptest2
Every time, I get the following:
/usr/bin/ld: /tmp/cc71SQmy.o: in function `main':
cliptest2.cpp:(.text+0x47): undefined reference to `clip::set_text(std::__cxx11::basic_string<char, std::char_traits, std::allocator > const&)'
collect2: error: ld returned 1 exit status
I do understand how the linker works and have gone through dozens of other questions with similar errors. However, given that I am building the third party library and linking it into my sample program, I don't understand why the set_text() method is not being resolved.
Edit: I've tried a few things, also as a result of the comments below. The source code for the clip library resides at ~/git/clip, and I am compiling cliptest2.cpp from the home directory itself. Therefore, adjusting the command suggested by #MathiasSchmid to my environment, I end up with this:
g++ cliptest2.cpp -I git -L git/clip -lclip -lxcb -lpthread -o cliptest2
I run this on my Kubuntu 20.04 LTS, and get all the following errors:
daniel#orion:~$ g++ cliptest2.cpp -I git -L git/clip -lclip -lxcb -lpthread -o cliptest2
/usr/bin/ld: git/clip/libclip.a(clip_x11.cpp.o): in function `clip::x11::write_data_fn(png_struct_def*, unsigned char*, unsigned long)':
clip_x11.cpp:(.text+0x4f): undefined reference to `png_get_io_ptr'
/usr/bin/ld: git/clip/libclip.a(clip_x11.cpp.o): in function `clip::x11::write_png(clip::image const&, std::vector<unsigned char, std::allocator<unsigned char> >&)':
clip_x11.cpp:(.text+0x117): undefined reference to `png_create_write_struct'
/usr/bin/ld: clip_x11.cpp:(.text+0x13a): undefined reference to `png_create_info_struct'
/usr/bin/ld: clip_x11.cpp:(.text+0x158): undefined reference to `png_destroy_write_struct'
/usr/bin/ld: clip_x11.cpp:(.text+0x17d): undefined reference to `png_set_longjmp_fn'
/usr/bin/ld: clip_x11.cpp:(.text+0x1a5): undefined reference to `png_destroy_write_struct'
/usr/bin/ld: clip_x11.cpp:(.text+0x1cb): undefined reference to `png_set_write_fn'
/usr/bin/ld: clip_x11.cpp:(.text+0x232): undefined reference to `png_set_IHDR'
/usr/bin/ld: clip_x11.cpp:(.text+0x249): undefined reference to `png_write_info'
/usr/bin/ld: clip_x11.cpp:(.text+0x255): undefined reference to `png_set_packing'
/usr/bin/ld: clip_x11.cpp:(.text+0x268): undefined reference to `png_get_rowbytes'
/usr/bin/ld: clip_x11.cpp:(.text+0x27a): undefined reference to `png_malloc'
/usr/bin/ld: clip_x11.cpp:(.text+0x3cd): undefined reference to `png_write_rows'
/usr/bin/ld: clip_x11.cpp:(.text+0x3e9): undefined reference to `png_free'
/usr/bin/ld: clip_x11.cpp:(.text+0x3fc): undefined reference to `png_write_end'
/usr/bin/ld: clip_x11.cpp:(.text+0x40f): undefined reference to `png_destroy_write_struct'
/usr/bin/ld: git/clip/libclip.a(clip_x11.cpp.o): in function `clip::x11::read_data_fn(png_struct_def*, unsigned char*, unsigned long)':
clip_x11.cpp:(.text+0x45d): undefined reference to `png_get_io_ptr'
/usr/bin/ld: git/clip/libclip.a(clip_x11.cpp.o): in function `clip::x11::read_png(unsigned char const*, unsigned long, clip::image*, clip::image_spec*)':
clip_x11.cpp:(.text+0x575): undefined reference to `png_create_read_struct'
/usr/bin/ld: clip_x11.cpp:(.text+0x5a1): undefined reference to `png_create_info_struct'
/usr/bin/ld: clip_x11.cpp:(.text+0x5cd): undefined reference to `png_destroy_read_struct'
/usr/bin/ld: clip_x11.cpp:(.text+0x5f5): undefined reference to `png_set_longjmp_fn'
/usr/bin/ld: clip_x11.cpp:(.text+0x628): undefined reference to `png_destroy_read_struct'
/usr/bin/ld: clip_x11.cpp:(.text+0x68f): undefined reference to `png_set_read_fn'
/usr/bin/ld: clip_x11.cpp:(.text+0x6a8): undefined reference to `png_read_info'
/usr/bin/ld: clip_x11.cpp:(.text+0x6ea): undefined reference to `png_get_IHDR'
/usr/bin/ld: clip_x11.cpp:(.text+0x747): undefined reference to `png_get_rowbytes'
/usr/bin/ld: clip_x11.cpp:(.text+0x8bf): undefined reference to `png_set_strip_16'
/usr/bin/ld: clip_x11.cpp:(.text+0x8ce): undefined reference to `png_set_packing'
/usr/bin/ld: clip_x11.cpp:(.text+0x8dd): undefined reference to `png_set_expand_gray_1_2_4_to_8'
/usr/bin/ld: clip_x11.cpp:(.text+0x8ec): undefined reference to `png_set_palette_to_rgb'
/usr/bin/ld: clip_x11.cpp:(.text+0x8fb): undefined reference to `png_set_gray_to_rgb'
/usr/bin/ld: clip_x11.cpp:(.text+0x90a): undefined reference to `png_set_tRNS_to_alpha'
/usr/bin/ld: clip_x11.cpp:(.text+0x919): undefined reference to `png_set_interlace_handling'
/usr/bin/ld: clip_x11.cpp:(.text+0x938): undefined reference to `png_read_update_info'
/usr/bin/ld: clip_x11.cpp:(.text+0x95a): undefined reference to `png_malloc'
/usr/bin/ld: clip_x11.cpp:(.text+0x9ab): undefined reference to `png_malloc'
/usr/bin/ld: clip_x11.cpp:(.text+0xa19): undefined reference to `png_read_rows'
/usr/bin/ld: clip_x11.cpp:(.text+0xbe0): undefined reference to `png_free'
/usr/bin/ld: clip_x11.cpp:(.text+0xc05): undefined reference to `png_free'
/usr/bin/ld: clip_x11.cpp:(.text+0xc4b): undefined reference to `png_destroy_read_struct'
collect2: error: ld returned 1 exit status
It is still not clear to me what the problem here is.
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