I complie my c++ program by input:
g++ main.cpp crypto/Sign.cpp -o main -lssl -lcrypto && ./main
Unfortunately, I got these output:
/tmp/ccEDu0Qv.o: In function `Sign::md_ctx_sign_init(SignatureScheme, evp_md_ctx_st*)':
Sign.cpp:(.text+0x1b): undefined reference to `EVP_MD_CTX_reset'
Sign.cpp:(.text+0x104): undefined reference to `EVP_sha3_224'
Sign.cpp:(.text+0x137): undefined reference to `EVP_sha3_256'
Sign.cpp:(.text+0x16a): undefined reference to `EVP_sha3_384'
Sign.cpp:(.text+0x196): undefined reference to `EVP_sha3_512'
/tmp/ccEDu0Qv.o: In function `Sign::md_ctx_veri_init(SignatureScheme, evp_md_ctx_st*)':
Sign.cpp:(.text+0x22f): undefined reference to `EVP_MD_CTX_reset'
Sign.cpp:(.text+0x318): undefined reference to `EVP_sha3_224'
Sign.cpp:(.text+0x34b): undefined reference to `EVP_sha3_256'
Sign.cpp:(.text+0x37e): undefined reference to `EVP_sha3_384'
Sign.cpp:(.text+0x3aa): undefined reference to `EVP_sha3_512'
/tmp/ccEDu0Qv.o: In function `Sign::sign_hash(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, evp_md_ctx_st*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&)':
Sign.cpp:(.text+0x4a9): undefined reference to `EVP_MD_CTX_free'
Sign.cpp:(.text+0x53f): undefined reference to `EVP_MD_CTX_free'
/tmp/ccEDu0Qv.o: In function `Sign::get_public_key(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&)':
Sign.cpp:(.text+0x697): undefined reference to `EVP_PKEY_get0_EC_KEY'
/tmp/ccEDu0Qv.o: In function `Sign::get_private_key(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&)':
Sign.cpp:(.text+0x85b): undefined reference to `EVP_PKEY_get0_EC_KEY'
/tmp/ccEDu0Qv.o: In function `Sign::EC_sign(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&, SignatureScheme)':
Sign.cpp:(.text+0xa4a): undefined reference to `EVP_MD_CTX_new'
/tmp/ccEDu0Qv.o: In function `Sign::EC_veri(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&, SignatureScheme)':
Sign.cpp:(.text+0xc56): undefined reference to `EVP_MD_CTX_new'
collect2: error: ld returned 1 exit status
So, what's wrong happend? How can I fix this problem?
The openssl I use is:
#:~$ which -a openssl
/usr/local/bin/openssl
/usr/bin/openssl
#:~$ openssl version
OpenSSL 1.1.1-pre5 (beta) 17 Apr 2018
In crypto/Sign.h, it include:
#include <openssl/conf.h>
#include <openssl/ec.h> // for EC_GROUP_new_by_curve_name, EC_GROUP_free, EC_KEY_new, EC_KEY_set_group, EC_KEY_generate_key, EC_KEY_free
#include <openssl/ecdsa.h> // for ECDSA_do_sign, ECDSA_do_verify
#include <openssl/err.h>
#include <openssl/evp.h>
#include <iostream>
#include <string>
Related
OK.
It's been a while since I wrote any C++.
And I'm rusty.
So what am I doing wrong here, and why?
#include <iostream>
std::string hello() {
return "another green world";
}
int main(int argc, char **argv) {
std::cout << hello() << std::endl;
return 0;
}
Then compiling with :
gcc test.cpp -o test
gives me
/tmp/ccxCCo47.o: In function `hello[abi:cxx11]()':
test.cpp:(.text+0x34): undefined reference to `std::allocator<char>::allocator()'
test.cpp:(.text+0x4b): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(char const*, std::allocator<char> const&)'
test.cpp:(.text+0x57): undefined reference to `std::allocator<char>::~allocator()'
test.cpp:(.text+0x7b): undefined reference to `std::allocator<char>::~allocator()'
/tmp/ccxCCo47.o: In function `main':
test.cpp:(.text+0xcb): undefined reference to `std::cout'
test.cpp:(.text+0xd0): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::operator<< <char, std::char_traits<char>, std::allocator<char> >(std::basic_ostream<char, std::char_traits<char> >&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
test.cpp:(.text+0xda): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::endl<char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&)'
test.cpp:(.text+0xe5): undefined reference to `std::ostream::operator<<(std::ostream& (*)(std::ostream&))'
test.cpp:(.text+0xf1): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string()'
test.cpp:(.text+0x116): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string()'
/tmp/ccxCCo47.o: In function `__static_initialization_and_destruction_0(int, int)':
test.cpp:(.text+0x156): undefined reference to `std::ios_base::Init::Init()'
test.cpp:(.text+0x16b): undefined reference to `std::ios_base::Init::~Init()'
/tmp/ccxCCo47.o:(.data.rel.local.DW.ref.__gxx_personality_v0[DW.ref.__gxx_personality_v0]+0x0): undefined reference to `__gxx_personality_v0'
collect2: error: ld returned 1 exit status
You need to include your header file.
#include <iostream>
Also, try compiling with g++ instead of gcc.
g++ test.cpp
My code won't compile and I don't understand the cryptic output from the compiler. Can you spot the error?
main.cpp
#include <vector>
#include <string>
int main() {
std::vector <std::string> myVar;
return 0;
}
Then in bash:
$ gcc main.cpp
/tmp/ccvmVBRq.o: In function `__gnu_cxx::new_allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >::deallocate(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >*, unsigned long)':
main.cpp:(.text._ZN9__gnu_cxx13new_allocatorINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEE10deallocateEPS6_m[_ZN9__gnu_cxx13new_allocatorINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEE10deallocateEPS6_m]+0x1c): undefined reference to `operator delete(void*)'
/tmp/ccvmVBRq.o: In function `void std::_Destroy<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >*)':
main.cpp:(.text._ZSt8_DestroyINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEEvPT_[_ZSt8_DestroyINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEEvPT_]+0x14): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string()'
/tmp/ccvmVBRq.o:(.data.rel.local.DW.ref.__gxx_personality_v0[DW.ref.__gxx_personality_v0]+0x0): undefined reference to `__gxx_personality_v0'
collect2: error: ld returned 1 exit status
This is C++ code, so you have to compile it with g++. Try:
$ g++ main.cpp
This question already has answers here:
What is an undefined reference/unresolved external symbol error and how do I fix it?
(39 answers)
Closed 5 years ago.
I am trying to use program_options from Boost in my project.
I am using Windows 10 but compiling on the ubuntu subsystem using g++.
I installed on boost using sudo apt install libboost-all-dev and then proceeded to try out their example file found here.
Then I compiled using g++ first.cpp and received the following error:
/tmp/cc9iLK5U.o: In function `main':
first.cpp:(.text+0x2e): undefined reference to `boost::program_options::options_description::m_default_line_length'
first.cpp:(.text+0x3a): undefined reference to `boost::program_options::options_description::m_default_line_length'
first.cpp:(.text+0x80): undefined reference to `boost::program_options::options_description::options_description(std::__cxx11::basic_string<char, std::char_traits<char>, std::allo
cator<char> > const&, unsigned int, unsigned int)'
first.cpp:(.text+0xb5): undefined reference to `boost::program_options::options_description::add_options()'
first.cpp:(.text+0xd5): undefined reference to `boost::program_options::options_description_easy_init::operator()(char const*, char const*)'
first.cpp:(.text+0xea): undefined reference to `boost::program_options::options_description_easy_init::operator()(char const*, boost::program_options::value_semantic const*, char
const*)'
first.cpp:(.text+0xf9): undefined reference to `boost::program_options::variables_map::variables_map()'
first.cpp:(.text+0x159): undefined reference to `boost::program_options::store(boost::program_options::basic_parsed_options<char> const&, boost::program_options::variables_map&, b
ool)'
first.cpp:(.text+0x186): undefined reference to `boost::program_options::notify(boost::program_options::variables_map&)'
first.cpp:(.text+0x20b): undefined reference to `boost::program_options::operator<<(std::ostream&, boost::program_options::options_description const&)'
/tmp/cc9iLK5U.o: In function `boost::program_options::error_with_option_name::~error_with_option_name()':
first.cpp:(.text._ZN5boost15program_options22error_with_option_nameD2Ev[_ZN5boost15program_options22error_with_option_nameD5Ev]+0x10): undefined reference to `vtable for boost::pr
ogram_options::error_with_option_name'
/tmp/cc9iLK5U.o: In function `boost::program_options::validation_error::validation_error(boost::program_options::validation_error::kind_t, std::__cxx11::basic_string<char, std::ch
ar_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int)':
first.cpp:(.text._ZN5boost15program_options16validation_errorC2ENS1_6kind_tERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESA_i[_ZN5boost15program_options16validation_error
C5ENS1_6kind_tERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESA_i]+0x3d): undefined reference to `boost::program_options::validation_error::get_template[abi:cxx11](boost::
program_options::validation_error::kind_t)'
first.cpp:(.text._ZN5boost15program_options16validation_errorC2ENS1_6kind_tERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESA_i[_ZN5boost15program_options16validation_error
C5ENS1_6kind_tERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESA_i]+0x5b): undefined reference to `boost::program_options::error_with_option_name::error_with_option_name(st
d::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::
__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int)'
/tmp/cc9iLK5U.o: In function `boost::program_options::value_semantic_codecvt_helper<char>::value_semantic_codecvt_helper()':
first.cpp:(.text._ZN5boost15program_options29value_semantic_codecvt_helperIcEC2Ev[_ZN5boost15program_options29value_semantic_codecvt_helperIcEC5Ev]+0x19): undefined reference to `
vtable for boost::program_options::value_semantic_codecvt_helper<char>'
/tmp/cc9iLK5U.o: In function `boost::program_options::value_semantic_codecvt_helper<char>::~value_semantic_codecvt_helper()':
first.cpp:(.text._ZN5boost15program_options29value_semantic_codecvt_helperIcED2Ev[_ZN5boost15program_options29value_semantic_codecvt_helperIcED5Ev]+0xd): undefined reference to `v
table for boost::program_options::value_semantic_codecvt_helper<char>'
/tmp/cc9iLK5U.o: In function `boost::program_options::variables_map::operator[](std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) const':
first.cpp:(.text._ZNK5boost15program_options13variables_mapixERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE[_ZNK5boost15program_options13variables_mapixERKNSt7__cxx1112ba
sic_stringIcSt11char_traitsIcESaIcEEE]+0x1f): undefined reference to `boost::program_options::abstract_variables_map::operator[](std::__cxx11::basic_string<char, std::char_traits<
char>, std::allocator<char> > const&) const'
/tmp/cc9iLK5U.o: In function `boost::program_options::basic_command_line_parser<char>::basic_command_line_parser(int, char const* const*)':
first.cpp:(.text._ZN5boost15program_options25basic_command_line_parserIcEC2EiPKPKc[_ZN5boost15program_options25basic_command_line_parserIcEC5EiPKPKc]+0x81): undefined reference to
`boost::program_options::detail::cmdline::cmdline(std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_
string<char, std::char_traits<char>, std::allocator<char> > > > const&)'
/tmp/cc9iLK5U.o: In function `boost::program_options::basic_command_line_parser<char>::options(boost::program_options::options_description const&)':
first.cpp:(.text._ZN5boost15program_options25basic_command_line_parserIcE7optionsERKNS0_19options_descriptionE[_ZN5boost15program_options25basic_command_line_parserIcE7optionsERKN
S0_19options_descriptionE]+0x1f): undefined reference to `boost::program_options::detail::cmdline::set_options_description(boost::program_options::options_description const&)'
/tmp/cc9iLK5U.o: In function `boost::program_options::basic_command_line_parser<char>::style(int)':
first.cpp:(.text._ZN5boost15program_options25basic_command_line_parserIcE5styleEi[_ZN5boost15program_options25basic_command_line_parserIcE5styleEi]+0x1c): undefined reference to `
boost::program_options::detail::cmdline::style(int)'
/tmp/cc9iLK5U.o: In function `boost::program_options::basic_command_line_parser<char>::extra_parser(boost::function1<std::pair<std::__cxx11::basic_string<char, std::char_traits<ch
ar>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::__cxx11::basic_string<char, std::char_traits<char>, std::alloc
ator<char> > const&>)':
first.cpp:(.text._ZN5boost15program_options25basic_command_line_parserIcE12extra_parserENS_9function1ISt4pairINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESA_ERKSA_EE[_ZN5b
oost15program_options25basic_command_line_parserIcE12extra_parserENS_9function1ISt4pairINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESA_ERKSA_EE]+0x42): undefined reference
to `boost::program_options::detail::cmdline::set_additional_parser(boost::function1<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std
::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&>)'
/tmp/cc9iLK5U.o: In function `boost::program_options::basic_command_line_parser<char>::run()':
first.cpp:(.text._ZN5boost15program_options25basic_command_line_parserIcE3runEv[_ZN5boost15program_options25basic_command_line_parserIcE3runEv]+0x28): undefined reference to `boos
t::program_options::detail::cmdline::get_canonical_option_prefix()'
first.cpp:(.text._ZN5boost15program_options25basic_command_line_parserIcE3runEv[_ZN5boost15program_options25basic_command_line_parserIcE3runEv]+0x54): undefined reference to `boos
t::program_options::detail::cmdline::run()'
/tmp/cc9iLK5U.o: In function `std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::cha
r_traits<char>, std::allocator<char> > > > boost::program_options::to_internal<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >(std::vector<std::_
_cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > const
&)':
first.cpp:(.text._ZN5boost15program_options11to_internalINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEEESt6vectorIS7_SaIS7_EERKS8_IT_SaISB_EE[_ZN5boost15program_options11to
_internalINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEEESt6vectorIS7_SaIS7_EERKS8_IT_SaISB_EE]+0x6c): undefined reference to `boost::program_options::to_internal(std::__cx
x11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
/tmp/cc9iLK5U.o:(.rodata._ZTVN5boost15program_options11typed_valueIdcEE[_ZTVN5boost15program_options11typed_valueIdcEE]+0x38): undefined reference to `boost::program_options::valu
e_semantic_codecvt_helper<char>::parse(boost::any&, std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic
_string<char, std::char_traits<char>, std::allocator<char> > > > const&, bool) const'
/tmp/cc9iLK5U.o:(.rodata._ZTVN5boost15program_options20invalid_option_valueE[_ZTVN5boost15program_options20invalid_option_valueE]+0x20): undefined reference to `boost::program_opt
ions::error_with_option_name::what() const'
/tmp/cc9iLK5U.o:(.rodata._ZTVN5boost15program_options20invalid_option_valueE[_ZTVN5boost15program_options20invalid_option_valueE]+0x30): undefined reference to `boost::program_opt
ions::error_with_option_name::substitute_placeholders(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) const'
/tmp/cc9iLK5U.o:(.rodata._ZTVN5boost15program_options16validation_errorE[_ZTVN5boost15program_options16validation_errorE]+0x20): undefined reference to `boost::program_options::er
ror_with_option_name::what() const'
/tmp/cc9iLK5U.o:(.rodata._ZTVN5boost15program_options16validation_errorE[_ZTVN5boost15program_options16validation_errorE]+0x30): undefined reference to `boost::program_options::er
ror_with_option_name::substitute_placeholders(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) const'
/tmp/cc9iLK5U.o:(.rodata._ZTIN5boost15program_options11typed_valueIdcEE[_ZTIN5boost15program_options11typed_valueIdcEE]+0x18): undefined reference to `typeinfo for boost::program_
options::value_semantic_codecvt_helper<char>'
/tmp/cc9iLK5U.o:(.rodata._ZTIN5boost15program_options16validation_errorE[_ZTIN5boost15program_options16validation_errorE]+0x10): undefined reference to `typeinfo for boost::progra
m_options::error_with_option_name'
/tmp/cc9iLK5U.o: In function `boost::program_options::variables_map::~variables_map()':
first.cpp:(.text._ZN5boost15program_options13variables_mapD2Ev[_ZN5boost15program_options13variables_mapD5Ev]+0xe): undefined reference to `vtable for boost::program_options::vari
ables_map'
/tmp/cc9iLK5U.o: In function `boost::program_options::typed_value<double, char>::name() const':
first.cpp:(.text._ZNK5boost15program_options11typed_valueIdcE4nameEv[_ZNK5boost15program_options11typed_valueIdcE4nameEv]+0x41): undefined reference to `boost::program_options::ar
g[abi:cxx11]'
/tmp/cc9iLK5U.o: In function `void boost::program_options::validate<double, char>(boost::any&, std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<
char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > const&, double*, long)':
first.cpp:(.text._ZN5boost15program_options8validateIdcEEvRNS_3anyERKSt6vectorINSt7__cxx1112basic_stringIT0_St11char_traitsIS7_ESaIS7_EEESaISB_EEPT_l[_ZN5boost15program_options8va
lidateIdcEEvRNS_3anyERKSt6vectorINSt7__cxx1112basic_stringIT0_St11char_traitsIS7_ESaIS7_EEESaISB_EEPT_l]+0x44): undefined reference to `boost::program_options::validators::check_f
irst_occurrence(boost::any const&)'
first.cpp:(.text._ZN5boost15program_options8validateIdcEEvRNS_3anyERKSt6vectorINSt7__cxx1112basic_stringIT0_St11char_traitsIS7_ESaIS7_EEESaISB_EEPT_l[_ZN5boost15program_options8va
lidateIdcEEvRNS_3anyERKSt6vectorINSt7__cxx1112basic_stringIT0_St11char_traitsIS7_ESaIS7_EEESaISB_EEPT_l]+0x141): undefined reference to `boost::program_options::invalid_option_val
ue::invalid_option_value(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
/tmp/cc9iLK5U.o: In function `boost::program_options::error_with_option_name::error_with_option_name(boost::program_options::error_with_option_name const&)':
first.cpp:(.text._ZN5boost15program_options22error_with_option_nameC2ERKS1_[_ZN5boost15program_options22error_with_option_nameC5ERKS1_]+0x25): undefined reference to `vtable for b
oost::program_options::error_with_option_name'
/tmp/cc9iLK5U.o:(.rodata._ZTVN5boost16exception_detail10clone_implINS0_19error_info_injectorINS_15program_options16validation_errorEEEEE[_ZTVN5boost16exception_detail10clone_implI
NS0_19error_info_injectorINS_15program_options16validation_errorEEEEE]+0x28): undefined reference to `boost::program_options::error_with_option_name::what() const'
/tmp/cc9iLK5U.o:(.rodata._ZTVN5boost16exception_detail10clone_implINS0_19error_info_injectorINS_15program_options16validation_errorEEEEE[_ZTVN5boost16exception_detail10clone_implI
NS0_19error_info_injectorINS_15program_options16validation_errorEEEEE]+0x38): undefined reference to `boost::program_options::error_with_option_name::substitute_placeholders(std::
__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) const'
/tmp/cc9iLK5U.o:(.rodata._ZTVN5boost16exception_detail19error_info_injectorINS_15program_options16validation_errorEEE[_ZTVN5boost16exception_detail19error_info_injectorINS_15progr
am_options16validation_errorEEE]+0x20): undefined reference to `boost::program_options::error_with_option_name::what() const'
/tmp/cc9iLK5U.o:(.rodata._ZTVN5boost16exception_detail19error_info_injectorINS_15program_options16validation_errorEEE[_ZTVN5boost16exception_detail19error_info_injectorINS_15progr
am_options16validation_errorEEE]+0x30): undefined reference to `boost::program_options::error_with_option_name::substitute_placeholders(std::__cxx11::basic_string<char, std::char_
traits<char>, std::allocator<char> > const&) const'
/tmp/cc9iLK5U.o:(.rodata._ZTVN5boost16exception_detail10clone_implINS0_19error_info_injectorINS_15program_options20invalid_option_valueEEEEE[_ZTVN5boost16exception_detail10clone_i
mplINS0_19error_info_injectorINS_15program_options20invalid_option_valueEEEEE]+0x28): undefined reference to `boost::program_options::error_with_option_name::what() const'
/tmp/cc9iLK5U.o:(.rodata._ZTVN5boost16exception_detail10clone_implINS0_19error_info_injectorINS_15program_options20invalid_option_valueEEEEE[_ZTVN5boost16exception_detail10clone_i
mplINS0_19error_info_injectorINS_15program_options20invalid_option_valueEEEEE]+0x38): undefined reference to `boost::program_options::error_with_option_name::substitute_placeholde
rs(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) const'
/tmp/cc9iLK5U.o:(.rodata._ZTVN5boost16exception_detail19error_info_injectorINS_15program_options20invalid_option_valueEEE[_ZTVN5boost16exception_detail19error_info_injectorINS_15p
rogram_options20invalid_option_valueEEE]+0x20): undefined reference to `boost::program_options::error_with_option_name::what() const'
/tmp/cc9iLK5U.o:(.rodata._ZTVN5boost16exception_detail19error_info_injectorINS_15program_options20invalid_option_valueEEE[_ZTVN5boost16exception_detail19error_info_injectorINS_15p
rogram_options20invalid_option_valueEEE]+0x30): undefined reference to `boost::program_options::error_with_option_name::substitute_placeholders(std::__cxx11::basic_string<char, st
d::char_traits<char>, std::allocator<char> > const&) const'
collect2: error: ld returned 1 exit status
I am not sure if I missed a step or is it something related to WSL it self.
Turns out the problem is not related to WSL. I just had to add the appropriate links:
c++ first.cpp -lboost_program_options
I'm trying to build a program with some external/3rd party dependencies, but I keep getting undefined reference errors to functions/objects that I'm sure are being linked:
g++ -m64 -pthread -ljpeg -lrt -s -o build/release/darwin_socket build/release/main.o build/release/DarwinRobot.o build/release/dyn_system.o build/release/writefilestuff.o -lCppController /usr/local/webots/resources/projects/robots/darwin-op/libraries/darwin/libdarwin.so ../../lib/OPKinematics/lib/libOPKinematics64.a -lpthread -lipsocket -lboost_system -lboost_serialization -lm -L"/usr/local/webots/lib" -lController -lCppController
build/release/DarwinRobot.o: In function `webots::DarwinRobot::DarwinRobot()':
/home/code/cpp/darwin/controllers/darwin_socket/src/DarwinRobot.cpp:63: undefined reference to `webots::Robot::getLED(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
/home/code/cpp/darwin/controllers/darwin_socket/src/DarwinRobot.cpp:65: undefined reference to `webots::Robot::getLED(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
/home/code/cpp/darwin/controllers/darwin_socket/src/DarwinRobot.cpp:72: undefined reference to `webots::Robot::getGyro(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
/home/code/cpp/darwin/controllers/darwin_socket/src/DarwinRobot.cpp:75: undefined reference to `webots::Robot::getAccelerometer(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
/home/code/cpp/darwin/controllers/darwin_socket/src/DarwinRobot.cpp:78: undefined reference to `webots::Robot::getServo(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
/home/code/cpp/darwin/controllers/darwin_socket/src/DarwinRobot.cpp:80: undefined reference to `webots::Robot::getServo(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
/home/code/cpp/darwin/controllers/darwin_socket/src/DarwinRobot.cpp:88: undefined reference to `webots::Robot::getServo(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
/home/code/cpp/darwin/controllers/darwin_socket/src/DarwinRobot.cpp:90: undefined reference to `webots::Robot::getServo(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
/home/code/cpp/darwin/controllers/darwin_socket/src/DarwinRobot.cpp:101: undefined reference to `webots::Robot::getServo(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
build/release/DarwinRobot.o:/home/code/cpp/darwin/controllers/darwin_socket/src/DarwinRobot.cpp:103: more undefined references to `webots::Robot::getServo(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)' follow
build/release/DarwinRobot.o: In function `webots::DarwinRobot::DarwinRobot()':
/home/code/cpp/darwin/controllers/darwin_socket/src/DarwinRobot.cpp:118: undefined reference to `webots::Robot::getTouchSensor(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
/home/code/cpp/darwin/controllers/darwin_socket/src/DarwinRobot.cpp:120: undefined reference to `webots::Robot::getTouchSensor(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
/home/code/cpp/darwin/controllers/darwin_socket/src/DarwinRobot.cpp:139: undefined reference to `webots::Robot::getTouchSensor(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
/home/code/cpp/darwin/controllers/darwin_socket/src/DarwinRobot.cpp:141: undefined reference to `webots::Robot::getTouchSensor(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
build/release/DarwinRobot.o: In function `webots::DarwinRobot::savePosition()':
/home/code/cpp/darwin/controllers/darwin_socket/src/DarwinRobot.cpp:170: undefined reference to `webots::Supervisor::getFromDef(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) const'
/home/code/cpp/darwin/controllers/darwin_socket/src/DarwinRobot.cpp:170: undefined reference to `webots::Node::getField(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) const'
/home/code/cpp/darwin/controllers/darwin_socket/src/DarwinRobot.cpp:171: undefined reference to `webots::Supervisor::getFromDef(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) const'
/home/code/cpp/darwin/controllers/darwin_socket/src/DarwinRobot.cpp:171: undefined reference to `webots::Node::getField(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) const'
/home/code/cpp/darwin/controllers/darwin_socket/src/DarwinRobot.cpp:173: undefined reference to `webots::Supervisor::getFromDef(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) const'
build/release/DarwinRobot.o: In function `webots::DarwinRobot::checkFall()':
/home/code/cpp/darwin/controllers/darwin_socket/src/DarwinRobot.cpp:1007: undefined reference to `webots::Supervisor::getFromDef(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) const'
/home/code/cpp/darwin/controllers/darwin_socket/src/DarwinRobot.cpp:1007: undefined reference to `webots::Supervisor::getFromDef(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) const'
build/release/DarwinRobot.o:(.rodata._ZTVN6webots11DarwinRobotE[_ZTVN6webots11DarwinRobotE]+0x48): undefined reference to `webots::Robot::createAccelerometer(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) const'
build/release/DarwinRobot.o:(.rodata._ZTVN6webots11DarwinRobotE[_ZTVN6webots11DarwinRobotE]+0x50): undefined reference to `webots::Robot::createCamera(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) const'
build/release/DarwinRobot.o:(.rodata._ZTVN6webots11DarwinRobotE[_ZTVN6webots11DarwinRobotE]+0x58): undefined reference to `webots::Robot::createCompass(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) const'
build/release/DarwinRobot.o:(.rodata._ZTVN6webots11DarwinRobotE[_ZTVN6webots11DarwinRobotE]+0x60): undefined reference to `webots::Robot::createConnector(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) const'
build/release/DarwinRobot.o:(.rodata._ZTVN6webots11DarwinRobotE[_ZTVN6webots11DarwinRobotE]+0x68): undefined reference to `webots::Robot::createDisplay(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) const'
build/release/DarwinRobot.o:(.rodata._ZTVN6webots11DarwinRobotE[_ZTVN6webots11DarwinRobotE]+0x70): undefined reference to `webots::Robot::createDistanceSensor(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) const'
build/release/DarwinRobot.o:(.rodata._ZTVN6webots11DarwinRobotE[_ZTVN6webots11DarwinRobotE]+0x78): undefined reference to `webots::Robot::createEmitter(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) const'
build/release/DarwinRobot.o:(.rodata._ZTVN6webots11DarwinRobotE[_ZTVN6webots11DarwinRobotE]+0x80): undefined reference to `webots::Robot::createGPS(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) const'
build/release/DarwinRobot.o:(.rodata._ZTVN6webots11DarwinRobotE[_ZTVN6webots11DarwinRobotE]+0x88): undefined reference to `webots::Robot::createGyro(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) const'
build/release/DarwinRobot.o:(.rodata._ZTVN6webots11DarwinRobotE[_ZTVN6webots11DarwinRobotE]+0x90): undefined reference to `webots::Robot::createInertialUnit(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) const'
build/release/DarwinRobot.o:(.rodata._ZTVN6webots11DarwinRobotE[_ZTVN6webots11DarwinRobotE]+0x98): undefined reference to `webots::Robot::createLED(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) const'
build/release/DarwinRobot.o:(.rodata._ZTVN6webots11DarwinRobotE[_ZTVN6webots11DarwinRobotE]+0xa0): undefined reference to `webots::Robot::createLightSensor(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) const'
build/release/DarwinRobot.o:(.rodata._ZTVN6webots11DarwinRobotE[_ZTVN6webots11DarwinRobotE]+0xa8): undefined reference to `webots::Robot::createMotor(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) const'
build/release/DarwinRobot.o:(.rodata._ZTVN6webots11DarwinRobotE[_ZTVN6webots11DarwinRobotE]+0xb0): undefined reference to `webots::Robot::createPen(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) const'
build/release/DarwinRobot.o:(.rodata._ZTVN6webots11DarwinRobotE[_ZTVN6webots11DarwinRobotE]+0xb8): undefined reference to `webots::Robot::createPositionSensor(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) const'
build/release/DarwinRobot.o:(.rodata._ZTVN6webots11DarwinRobotE[_ZTVN6webots11DarwinRobotE]+0xc0): undefined reference to `webots::Robot::createReceiver(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) const'
build/release/DarwinRobot.o:(.rodata._ZTVN6webots11DarwinRobotE[_ZTVN6webots11DarwinRobotE]+0xc8): undefined reference to `webots::Robot::createServo(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) const'
build/release/DarwinRobot.o:(.rodata._ZTVN6webots11DarwinRobotE[_ZTVN6webots11DarwinRobotE]+0xd0): undefined reference to `webots::Robot::createTouchSensor(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) const'
build/release/DarwinRobot.o:(.rodata._ZTVN6webots11DarwinRobotE[_ZTVN6webots11DarwinRobotE]+0xf0): undefined reference to `webots::Supervisor::startMovie(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int, int, int, int, int, bool)'
build/release/DarwinRobot.o:(.rodata._ZTVN6webots11DarwinRobotE[_ZTVN6webots11DarwinRobotE]+0x100): undefined reference to `webots::Supervisor::setLabel(int, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, double, double, double, int, double)'
collect2: error: ld returned 1 exit status
make: *** [/usr/local/webots/resources/Makefile.include:530: build/release/darwin_socket] Error 1
I'm particularly sure that these objects are defined in libCppController.so, called by the flag -lCppController. Manually checking the shared object file (e.g. 'LED'):
objdump -TC lib/libCppController.so | grep LED
0000000000021a8c g DF .text 0000000000000053 Base webots::Robot::createLED(std::string const&) const
00000000000225c6 w DF .text 0000000000000037 Base webots::LED::LED(std::string const&)
00000000000219da g DF .text 00000000000000b2 Base webots::Robot::getLED(std::string const&)
000000000001e074 g DF .text 000000000000002c Base webots::LED::set(int)
00000000000225c6 w DF .text 0000000000000037 Base webots::LED::LED(std::string const&)
000000000001e0a0 g DF .text 0000000000000024 Base webots::LED::get() const
0000000000024018 w DO .rodata 000000000000000e Base typeinfo name for webots::LED
000000000022b650 w DO .data.rel.ro 0000000000000018 Base typeinfo for webots::LED
000000000001e106 w DF .text 0000000000000026 Base webots::LED::~LED()
000000000001e0c4 w DF .text 0000000000000041 Base webots::LED::~LED()
000000000001e0c4 w DF .text 0000000000000041 Base webots::LED::~LED()
000000000022b620 w DO .data.rel.ro 0000000000000028 Base vtable for webots::LED
So what exactly am I doing wrong here?
I have installed opencv recently . I am trying to do a bit if image processing using opencv and cuda. but I am getting an error like this
nvcc -o reference_hw1 reference_main.o student_func.o compare.o reference_calc.o -arch=sm_20 -Xcompiler -Wall -Xcompiler -Wextra -m64 -L /usr/lib
reference_main.o: In function `preProcess(uchar4**, unsigned char**, uchar4**, unsigned char**, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)':
reference_main.cpp:(.text+0xc4): undefined reference to `cv::imread(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int)'
reference_main.cpp:(.text+0x1b7): undefined reference to `cv::_OutputArray::_OutputArray(cv::Mat&)'
reference_main.cpp:(.text+0x1cd): undefined reference to `cv::_InputArray::_InputArray(cv::Mat const&)'
reference_main.cpp:(.text+0x1ea): undefined reference to `cv::cvtColor(cv::_InputArray const&, cv::_OutputArray const&, int, int)'
reference_main.o: In function `postProcess(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, unsigned char*)':
reference_main.cpp:(.text+0x45a): undefined reference to `cv::_InputArray::_InputArray(cv::Mat const&)'
reference_main.cpp:(.text+0x4a2): undefined reference to `cv::imwrite(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, cv::_InputArray const&, std::vector<int, std::allocator<int> > const&)'
reference_main.o: In function `generateReferenceImage(std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::basic_string<char, std::char_traits<char>, std::allocator<char> >)':
reference_main.cpp:(.text+0x5b2): undefined reference to `cv::imread(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int)'
reference_main.cpp:(.text+0x5d4): undefined reference to `cv::_InputArray::_InputArray(cv::Mat const&)'
reference_main.cpp:(.text+0x5ee): undefined reference to `cv::imwrite(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, cv::_InputArray const&, std::vector<int, std::allocator<int> > const&)'
reference_main.o: In function `cv::Mat::~Mat()':
reference_main.cpp:(.text._ZN2cv3MatD2Ev[_ZN2cv3MatD5Ev]+0x39): undefined reference to `cv::fastFree(void*)'
reference_main.o: In function `cv::Mat::operator=(cv::Mat const&)':
reference_main.cpp:(.text._ZN2cv3MataSERKS0_[cv::Mat::operator=(cv::Mat const&)]+0x111): undefined reference to `cv::Mat::copySize(cv::Mat const&)'
reference_main.o: In function `cv::Mat::create(int, int, int)':
reference_main.cpp:(.text._ZN2cv3Mat6createEiii[cv::Mat::create(int, int, int)]+0x96): undefined reference to `cv::Mat::create(int, int const*, int)'
reference_main.o: In function `cv::Mat::release()':
reference_main.cpp:(.text._ZN2cv3Mat7releaseEv[cv::Mat::release()]+0x47): undefined reference to `cv::Mat::deallocate()'
compare.o: In function `compareImages(std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::basic_string<char, std::char_traits<char>, std::allocator<char> >, bool, double, double)':
compare.cpp:(.text+0x4e): undefined reference to `cv::imread(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int)'
compare.cpp:(.text+0x6c): undefined reference to `cv::imread(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int)'
compare.cpp:(.text+0x8c): undefined reference to `cv::operator-(cv::Mat const&, cv::Mat const&)'
compare.cpp:(.text+0xa5): undefined reference to `cv::abs(cv::MatExpr const&)'
compare.cpp:(.text+0x15a): undefined reference to `cv::Mat::reshape(int, int) const'
compare.cpp:(.text+0x15f): undefined reference to `cv::noArray()'
compare.cpp:(.text+0x17b): undefined reference to `cv::_InputArray::_InputArray(cv::Mat const&)'
compare.cpp:(.text+0x1a9): undefined reference to `cv::minMaxLoc(cv::_InputArray const&, double*, double*, cv::Point_<int>*, cv::Point_<int>*, cv::_InputArray const&)'
compare.cpp:(.text+0x20c): undefined reference to `cv::operator-(cv::Mat const&, cv::Scalar_<double> const&)'
compare.cpp:(.text+0x22d): undefined reference to `cv::operator*(cv::MatExpr const&, double)'
compare.cpp:(.text+0x2d2): undefined reference to `cv::Mat::reshape(int, int) const'
compare.cpp:(.text+0x33d): undefined reference to `cv::_InputArray::_InputArray(cv::Mat const&)'
compare.cpp:(.text+0x375): undefined reference to `cv::imwrite(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, cv::_InputArray const&, std::vector<int, std::allocator<int> > const&)'
collect2: ld returned 1 exit status
make: *** [student] Error 1
I don't know why the error is like this. My Makefile is
NVCC= nvcc
###################################
# These are the default install #
# locations on most linux distros #
###################################
OPENCV_LIBPATH=/usr/lib
OPENCV_INCLUDEPATH=/usr/local/include
OPENCV_TROUBLE=
CUDA_INCLUDEPATH=/usr/local/cuda/include
NVCC_OPTS = -arch=sm_20 -Xcompiler -Wall -Xcompiler -Wextra -m64
GCC_OPTS = -Wall -Wextra -m64
student: reference_main.o student_func.o compare.o reference_calc.o Makefile
$(NVCC) -o reference_hw1 reference_main.o student_func.o compare.o reference_calc.o $(NVCC_OPTS) -L $(OPENCV_LIBPATH) $(OPENCV_TROUBLE)
reference_main.o: reference_main.cpp timer.h utils.h reference_calc.cpp compare.cpp reference_hw1.cpp
g++ -c reference_main.cpp $(GCC_OPTS) -I $(OPENCV_INCLUDEPATH) -I $(CUDA_INCLUDEPATH) $(OPENCV_LIBPATH) $(OPENCV_TROUBLE)
student_func.o: student_func.cu utils.h
nvcc -c student_func.cu $(NVCC_OPTS)
compare.o: compare.cpp compare.h
g++ -c compare.cpp -I $(CUDA_INCLUDEPATH) $(GCC_OPTS) -I $(OPENCV_INCLUDEPATH) $(OPENCV_LIBPATH) $(OPENCV_TROUBLE)
reference_calc.o: reference_calc.cpp reference_calc.h
g++ -c reference_calc.cpp -I $(CUDA_INCLUDEPATH) $(GCC_OPTS) -I $(OPENCV_INCLUDEPATH) $(OPENCV_LIBPATH) $(OPENCV_TROUBLE)
clean:
rm -f *.o *.png hw
In the directory of /usr/local/include
there are two folders opencv and opencv2 , so everything is fine according to the arrangements .
Now how to solve the problem ?
yesterday whole day got used in solution for this problem.
Please anybody help me.. Thanks in advance...
I tried all the methods.....