Hi I'm trying to use gnuplot-iostream, at the minute I'm just trying to get the code here working. When I try to combile I get errors in the linker saying:
In function `stream<int, boost::iostreams::file_descriptor_flags>':
/usr/include/boost/iostreams/stream.hpp:130: undefined reference to `boost::iostreams::file_descriptor_sink::file_descriptor_sink(int, boost::iostreams::file_descriptor_flags)'
In function `boost::iostreams::file_descriptor_sink boost::iostreams::detail::wrap<boost::iostreams::file_descriptor_sink>(boost::iostreams::file_descriptor_sink const&, boost::disable_if<boost::iostreams::is_std_io<boost::iostreams::file_descriptor_sink>, void>::type*)':
/usr/include/boost/iostreams/detail/wrap_unwrap.hpp:53: undefined reference to `boost::iostreams::file_descriptor_sink::file_descriptor_sink(boost::iostreams::file_descriptor_sink const&)'
In function `concept_adapter':
/usr/include/boost/iostreams/detail/adapter/concept_adapter.hpp:67: undefined reference to `boost::iostreams::file_descriptor_sink::file_descriptor_sink(boost::iostreams::file_descriptor_sink const&)'
/usr/include/boost/iostreams/detail/adapter/concept_adapter.hpp:38: undefined reference to `boost::iostreams::file_descriptor_sink::file_descriptor_sink(boost::iostreams::file_descriptor_sink const&)'
In function `long boost::iostreams::detail::write_device_impl<boost::iostreams::output>::write<boost::iostreams::file_descriptor_sink>(boost::iostreams::file_descriptor_sink&, boost::iostreams::char_type_of<boost::iostreams::file_descriptor_sink>::type const*, long)':
/usr/include/boost/iostreams/write.hpp:121: undefined reference to `boost::iostreams::file_descriptor::write(char const*, long)'
In function `void boost::iostreams::detail::close_impl<boost::iostreams::closable_tag>::close<boost::iostreams::file_descriptor_sink>(boost::iostreams::file_descriptor_sink&, std::_Ios_Openmode)':
/usr/include/boost/iostreams/close.hpp:224: undefined reference to `boost::iostreams::file_descriptor::close()'
In function `std::fpos<__mbstate_t> boost::iostreams::detail::seek_device_impl<boost::iostreams::any_tag>::seek<boost::iostreams::file_descriptor_sink>(boost::iostreams::file_descriptor_sink&, long, std::_Ios_Seekdir, std::_Ios_Openmode)':
/usr/include/boost/iostreams/seek.hpp:137: undefined reference to `boost::iostreams::file_descriptor::seek(long, std::_Ios_Seekdir)'
collect2: ld returned 1 exit status
Note I have boost installed and have previously compiled programs that use iostream.
Any help massively appreciated. Thanks
Ruling out the obvious... are you compiling with g++ -lboost_iostreams? If you can share some information about how the compiler and linker are being invoked it will make it easier to answer your question.
Run into exact problem when tried to use g++ with gnuplot-iostream library.
g++ prog.cpp -L/usr/lib -lboost_filesystem -lboost_system -lboost_iostreams
Resolved the issue for me - the code were compiled successfully with no errors.
Related
What are the linker flags I'm missing here?
I try to compile this on an Ubuntu 18.04 LTS and it fails, it works inside a Debian 9 docker image:
#include <boost/dll.hpp>
// Trying to compile it with:
// g++ -o program -lboost_filesystem -ldl -lboost_system program.cpp
int main() {
boost::dll::program_location();
return 0;
}
The error I get is:
/tmp/ccKlWUUd.o: In function `__static_initialization_and_destruction_0(int, int)':
program.cpp:(.text+0x68): undefined reference to `boost::system::generic_category()'
program.cpp:(.text+0x74): undefined reference to `boost::system::generic_category()'
program.cpp:(.text+0x80): undefined reference to `boost::system::system_category()'
/tmp/ccKlWUUd.o: In function `boost::system::error_code::error_code()':
program.cpp:(.text._ZN5boost6system10error_codeC2Ev[_ZN5boost6system10error_codeC5Ev]+0x17): undefined reference to `boost::system::system_category()'
/tmp/ccKlWUUd.o: In function `boost::system::error_category::std_category::equivalent(int, std::error_condition const&) const':
program.cpp:(.text._ZNK5boost6system14error_category12std_category10equivalentEiRKSt15error_condition[_ZNK5boost6system14error_category12std_category10equivalentEiRKSt15error_condition]+0xb8): undefined reference to `boost::system::generic_category()'
program.cpp:(.text._ZNK5boost6system14error_category12std_category10equivalentEiRKSt15error_condition[_ZNK5boost6system14error_category12std_category10equivalentEiRKSt15error_condition]+0xf3): undefined reference to `boost::system::generic_category()'
/tmp/ccKlWUUd.o: In function `boost::system::error_category::std_category::equivalent(std::error_code const&, int) const':
program.cpp:(.text._ZNK5boost6system14error_category12std_category10equivalentERKSt10error_codei[_ZNK5boost6system14error_category12std_category10equivalentERKSt10error_codei]+0xb8): undefined reference to `boost::system::generic_category()'
program.cpp:(.text._ZNK5boost6system14error_category12std_category10equivalentERKSt10error_codei[_ZNK5boost6system14error_category12std_category10equivalentERKSt10error_codei]+0xf3): undefined reference to `boost::system::generic_category()'
program.cpp:(.text._ZNK5boost6system14error_category12std_category10equivalentERKSt10error_codei[_ZNK5boost6system14error_category12std_category10equivalentERKSt10error_codei]+0x1d2): undefined reference to `boost::system::generic_category()'
/tmp/ccKlWUUd.o: In function `boost::dll::detail::report_error(boost::system::error_code const&, char const*)':
program.cpp:(.text._ZN5boost3dll6detail12report_errorERKNS_6system10error_codeEPKc[_ZN5boost3dll6detail12report_errorERKNS_6system10error_codeEPKc]+0x2a): undefined reference to `dlerror'
/tmp/ccKlWUUd.o: In function `boost::filesystem::read_symlink(boost::filesystem::path const&, boost::system::error_code&)':
program.cpp:(.text._ZN5boost10filesystem12read_symlinkERKNS0_4pathERNS_6system10error_codeE[_ZN5boost10filesystem12read_symlinkERKNS0_4pathERNS_6system10error_codeE]+0x36): undefined reference to `boost::filesystem::detail::read_symlink(boost::filesystem::path const&, boost::system::error_code*)'
collect2: error: ld returned 1 exit status
The system here is:
gcc: 7.0.3
boost: 1.65.1
libc6: 2.73
Your build command is in the wrong order, and order matters.
GCC reads left-to-right, taking symbols from libraries when it already knows it needs them. As you put program.cpp last, you don't make that known until all listed libraries have already been identified and discarded.
Put program.cpp first, then the libraries it needs.
g++ -o program program.cpp -lboost_filesystem -ldl -lboost_system
Yes, it's kind of weird. (Even weirder that it worked on Debian! Though apparently only some "recent" Linuxy distributions default --as-needed on, which is what causes the behaviour you see, showing that the behaviour isn't necessarily guaranteed. Perhaps Debian 9 just outright does not do that.)
More info:
Why does the order in which libraries are linked sometimes cause errors in GCC?
Trying to get boost libraries setup and compile/run some of the boost tutorials but am running into issues. I've googled around and tried some things, but nothing seems to be working. Would appreciate it if you guys could point me in the right direction.
Here's output from command line:
g++ -I /usr/local/boost_1_68_0/ timer.cpp -o timer
/tmp/ccLjn1qn.o: In function boost::system::system_category()':
timer.cpp:(.text._ZN5boost6system15system_categoryEv[_ZN5boost6system15system_categoryEv]+0x7): undefined reference toboost::system::detail::system_category_instance'
/tmp/ccLjn1qn.o: In function boost::system::generic_category()':
timer.cpp:(.text._ZN5boost6system16generic_categoryEv[_ZN5boost6system16generic_categoryEv]+0x7): undefined reference toboost::system::detail::generic_category_instance'
/tmp/ccLjn1qn.o: In function boost::asio::detail::posix_event::posix_event()':
timer.cpp:(.text._ZN5boost4asio6detail11posix_eventC2Ev[_ZN5boost4asio6detail11posix_eventC5Ev]+0x4d): undefined reference topthread_condattr_setclock'
/tmp/ccLjn1qn.o: In function boost::asio::detail::posix_thread::~posix_thread()':
timer.cpp:(.text._ZN5boost4asio6detail12posix_threadD2Ev[_ZN5boost4asio6detail12posix_threadD5Ev]+0x26): undefined reference topthread_detach'
/tmp/ccLjn1qn.o: In function boost::asio::detail::posix_thread::join()':
timer.cpp:(.text._ZN5boost4asio6detail12posix_thread4joinEv[_ZN5boost4asio6detail12posix_thread4joinEv]+0x2b): undefined reference topthread_join'
/tmp/ccLjn1qn.o: In function boost::asio::basic_waitable_timer<std::chrono::_V2::steady_clock, boost::asio::wait_traits<std::chrono::_V2::steady_clock> >::basic_waitable_timer(boost::asio::io_context&, std::chrono::duration<long, std::ratio<1l, 1000000000l> > const&)':
timer.cpp:(.text._ZN5boost4asio20basic_waitable_timerINSt6chrono3_V212steady_clockENS0_11wait_traitsIS4_EEEC2ERNS0_10io_contextERKNS2_8durationIlSt5ratioILl1ELl1000000000EEEE[_ZN5boost4asio20basic_waitable_timerINSt6chrono3_V212steady_clockENS0_11wait_traitsIS4_EEEC5ERNS0_10io_contextERKNS2_8durationIlSt5ratioILl1ELl1000000000EEEE]+0x41): undefined reference toboost::system::detail::system_category_instance'
/tmp/ccLjn1qn.o: In function boost::asio::basic_waitable_timer<std::chrono::_V2::steady_clock, boost::asio::wait_traits<std::chrono::_V2::steady_clock> >::wait()':
timer.cpp:(.text._ZN5boost4asio20basic_waitable_timerINSt6chrono3_V212steady_clockENS0_11wait_traitsIS4_EEE4waitEv[_ZN5boost4asio20basic_waitable_timerINSt6chrono3_V212steady_clockENS0_11wait_traitsIS4_EEE4waitEv]+0x26): undefined reference toboost::system::detail::system_category_instance'
/tmp/ccLjn1qn.o: In function boost::asio::detail::deadline_timer_service<boost::asio::detail::chrono_time_traits<std::chrono::_V2::steady_clock, boost::asio::wait_traits<std::chrono::_V2::steady_clock> > >::destroy(boost::asio::detail::deadline_timer_service<boost::asio::detail::chrono_time_traits<std::chrono::_V2::steady_clock, boost::asio::wait_traits<std::chrono::_V2::steady_clock> > >::implementation_type&)':
timer.cpp:(.text._ZN5boost4asio6detail22deadline_timer_serviceINS1_18chrono_time_traitsINSt6chrono3_V212steady_clockENS0_11wait_traitsIS6_EEEEE7destroyERNSA_19implementation_typeE[_ZN5boost4asio6detail22deadline_timer_serviceINS1_18chrono_time_traitsINSt6chrono3_V212steady_clockENS0_11wait_traitsIS6_EEEEE7destroyERNSA_19implementation_typeE]+0x29): undefined reference toboost::system::detail::system_category_instance'
collect2: error: ld returned 1 exit status
You need to learn about linking libraries (like -l boost_system -l boost_thread -l boost_asio). Boost documentation should have usage examples.
I would like to compile the following program that makes alignment of fasta sequences, the program is available in:
http://compbio.cs.princeton.edu/mems/
I have downloaded a zip file called sparseMEM and downloaded the g++ in Ubuntu Linux, in the directory created there is a Makefile archive, so I tried to compile with make. The problem is that I got the following error:
g++ -lpthread -O3 -DSIXTYFOURBITS mummer.o qsufsort.o sparseSA.o fasta.o -o mummer
mummer.o: In function `main':
mummer.cpp:(.text.startup+0x480): undefined reference to `pthread_create'
mummer.cpp:(.text.startup+0x4a8): undefined reference to `pthread_join'
sparseSA.o: In function `sparseSA::MEM(std::basic_string<char, std::char_traits<char>, std::allocator<char> >&, std::vector<match_t, std::allocator<match_t> >&, int, bool, int)':
sparseSA.cpp:(.text+0x3bbc): undefined reference to `pthread_create'
sparseSA.cpp:(.text+0x3be0): undefined reference to `pthread_join'
collect2: ld returned 1 exit status
make: *** [mummer] Error 1
how I can make it run?
also if somebody knows how to test this program it would be great
thanks
For Linux you need -pthread instead of -lpthread.
I am having lots of trouble getting a specific set of drivers working, called libnifalcon.
I am pretty sure that the installation was successful, but when I try to compile the example programs I get the errors:
mars#marslab:~/Documents/libnifalcon-1.0/examples/findfalcons$ g++ findfalcons.cpp
/tmp/cc8TtfGn.o: In function `runFalconTest()':
findfalcons.cpp:(.text+0x6b): undefined reference to `libnifalcon::FalconDevice::FalconDevice()'
findfalcons.cpp:(.text+0xdd): undefined reference to `libnifalcon::FalconDevice::getDeviceCount(unsigned int&)'
findfalcons.cpp:(.text+0x1bd): undefined reference to `libnifalcon::FalconDevice::open(unsigned int)'
findfalcons.cpp:(.text+0x224): undefined reference to `libnifalcon::FalconDevice::isFirmwareLoaded()'
findfalcons.cpp:(.text+0x2ac): undefined reference to `libnifalcon::FalconFirmware::loadFirmware(bool, unsigned int const&, unsigned char*)'
findfalcons.cpp:(.text+0x33b): undefined reference to `libnifalcon::FalconDevice::isFirmwareLoaded()'
findfalcons.cpp:(.text+0x3dd): undefined reference to `libnifalcon::FalconDevice::runIOLoop(unsigned int)'
findfalcons.cpp:(.text+0x504): undefined reference to `libnifalcon::FalconDevice::runIOLoop(unsigned int)'
findfalcons.cpp:(.text+0x512): undefined reference to `libnifalcon::FalconDevice::close()'
findfalcons.cpp:(.text+0x52b): undefined reference to `libnifalcon::FalconDevice::~FalconDevice()'
findfalcons.cpp:(.text+0x53f): undefined reference to `libnifalcon::FalconDevice::~FalconDevice()'
/tmp/cc8TtfGn.o: In function `void libnifalcon::FalconDevice::setFalconFirmware<libnifalcon::FalconFirmwareNovintSDK>()':
findfalcons.cpp:(.text._ZN11libnifalcon12FalconDevice17setFalconFirmwareINS_23FalconFirmwareNovintSDKEEEvv[void libnifalcon::FalconDevice::setFalconFirmware<libnifalcon::FalconFirmwareNovintSDK>()]+0x1d): undefined reference to `libnifalcon::FalconFirmwareNovintSDK::FalconFirmwareNovintSDK()'
collect2: ld returned 1 exit status
How can I verify the libraries are linked correctly? What can I do if they aren't?
You're not linking with anything, i.e.
g++ file.cpp
does not link to any libraries other than the standard library. You need to link with other modules or libraries, probably libnifalcon
g++ findfalcons.cpp -lnifalcon
or... you probably will need to do something like
g++ -L/path/to/libnifalcon findfalcons.cpp -lnifalcon
where -I tells where to look for libraries.
I'm getting this weird linker error using gcc, thought the code works fine when I use Visual Studio..
/tmp/ccfcdCxg.o: In function `global constructors keyed to main':
codechef_permut2.cpp:(.text+0xa): undefined reference to `std::ios_base::Init::Init()'
codechef_permut2.cpp:(.text+0x19): undefined reference to `std::ios_base::Init::~Init()'
/tmp/ccfcdCxg.o: In function `ambig(unsigned long)':
codechef_permut2.cpp:(.text+0x47): undefined reference to `operator new[](unsigned long)'
codechef_permut2.cpp:(.text+0x52): undefined reference to `operator new[](unsigned long)'
/tmp/ccfcdCxg.o:(.eh_frame+0x12): undefined reference to `__gxx_personality_v0'
collect2: ld returned 1 exit status
I dint post any code, because I think its not required but if someone feels I'll post it.
My guess is that you're using gcc rather than g++ to link your program. gcc won't include the C++ library unless you tell it to; g++ will.