I'm trying to use the mySQL c++ connector.
I have downloaded and extracted the binaries following the mysql guide https://dev.mysql.com/doc/connector-cpp/8.0/en/connector-cpp-installation-binary.html
When i include the xdevapi like so
#include <mysqlx/xdevapi.h>
I get the following errors
/tmp/cc6dzD4k.o: In function `mysqlx::string::operator std::__cxx11::basic_string, std::allocator >abi:cxx11 const':
/git_repos/FHM/Camera/Software/ExtractMetadata/Build/Linux/../../../mysql-connector-c++-8.0.13/include/mysqlx/devapi/common.h:115: undefined reference to `mysqlx::string::Impl::to_utf8[abi:cxx11](mysqlx::string const&)'
/tmp/cc6dzD4k.o: In function `mysqlx::DbDoc::DbDoc()':
/git_repos/FHM/Camera/Software/ExtractMetadata/Build/Linux/../../../mysql-connector-c++-8.0.13/include/mysqlx/devapi/document.h:153: undefined reference to `vtable for mysqlx::DbDoc'
/tmp/cc6dzD4k.o: In function mysqlx::DbDoc::~DbDoc()':
/git_repos/FHM/Camera/Software/ExtractMetadata/Build/Linux/../../../mysql-connector-c++-8.0.13/include/mysqlx/devapi/document.h:127: undefined reference tovtable for mysqlx::DbDoc'
/tmp/cc6dzD4k.o: In function mysqlx::Value::print(std::ostream&) const':
/git_repos/FHM/Camera/Software/ExtractMetadata/Build/Linux/../../../mysql-connector-c++-8.0.13/include/mysqlx/devapi/document.h:507: undefined reference tomysqlx::common::Value::print(std::ostream&) const'
/tmp/cc6dzD4k.o:(.rodata._ZTCN6mysqlx5ValueE0_NS_6common5ValueE[_ZTVN6mysqlx5ValueE]+0x18): undefined reference to typeinfo for mysqlx::common::Value'
/tmp/cc6dzD4k.o:(.rodata._ZTCN6mysqlx5ValueE0_NS_6common5ValueE[_ZTVN6mysqlx5ValueE]+0x20): undefined reference tomysqlx::common::Value::print(std::ostream&) const'
/tmp/cc6dzD4k.o:(.rodata._ZTIN6mysqlx5ValueE[_ZTIN6mysqlx5ValueE]+0x28): undefined reference to `typeinfo for mysqlx::common::Value'
collect2: error: ld returned 1 exit status
Makefile:2: recipe for target 'x86' failed
make: *** [x86] Error 1
My Makefile look like this:
g++ -I../../Src -I../../../Fee/Src \
-I/../../../OpenCV/include/opencv \
-I../../../OpenCV/include/opencv2 \
-I../../../mysql-connector-c++-8.0.13/include/ \
-L../../../OpenCV/lib/LinX86 \
-L../../../mysql-connector-c++-8.0.13/lib64/libmysqlcppconn8-static.a -lssl -lcrypto -lpthread \
-g -D LINUX -o extractmetadata ../../Src/extractMetadata.cpp ../../../Fee/Src/Status.cpp \
-std=c++11 \
-lopencv_world -lstdc++fs \
Does anyone know what I'm missing here?
You are not linking with the MySQL library:
-L../../../mysql-connector-c++-8.0.13/lib64/libmysqlcppconn8-static.a
Use:
../../../mysql-connector-c++-8.0.13/lib64/libmysqlcppconn8-static.a
or:
-L../../../mysql-connector-c++-8.0.13/lib64/ -lmysqlcppconn8-static
Related
I am trying to build gRPC in C++ by following c++ gRPC installation. My OS is Ubuntu20.4 LTS installed on Raspberry Pi 4.
When I typed this command "make -j"
$ cd grpc
$ mkdir -p cmake/build
$ pushd cmake/build
$ cmake -DgRPC_INSTALL=ON \
-DgRPC_BUILD_TESTS=OFF \
-DCMAKE_INSTALL_PREFIX=$MY_INSTALL_DIR \
../..
$ make -j
this error occurs.
[ 1%] Built target zlibstatic
・
・
[ 97%] Built target mimics_pcre_test
[ 97%] Built target possible_match_test
[ 97%] Built target set_test
[ 97%] Built target regexp_test
[ 97%] Built target search_test
[ 97%] Linking CXX executable bssl
/usr/bin/ld: CMakeFiles/bssl.dir/src/tool/transport_common.cc.o: in function `PrintConnectionInfo(bio_st*, ssl_st const*)':
transport_common.cc:(.text+0xd40): undefined reference to `X509_NAME_print_ex'
/usr/bin/ld: transport_common.cc:(.text+0xd74): undefined reference to `X509_NAME_print_ex'
/usr/bin/ld: libcrypto.a(trust_token.c.o):(.data.rel.ro+0x50): undefined reference to `voprf_exp2_generate_key'
/usr/bin/ld: libcrypto.a(trust_token.c.o):(.data.rel.ro+0x58): undefined reference to `voprf_exp2_client_key_from_bytes'
/usr/bin/ld: libcrypto.a(trust_token.c.o):(.data.rel.ro+0x60): undefined reference to `voprf_exp2_issuer_key_from_bytes'
/usr/bin/ld: libcrypto.a(trust_token.c.o):(.data.rel.ro+0x68): undefined reference to `voprf_exp2_blind'
/usr/bin/ld: libcrypto.a(trust_token.c.o):(.data.rel.ro+0x70): undefined reference to `voprf_exp2_sign'
/usr/bin/ld: libcrypto.a(trust_token.c.o):(.data.rel.ro+0x78): undefined reference to `voprf_exp2_unblind'
/usr/bin/ld: libcrypto.a(trust_token.c.o):(.data.rel.ro+0x80): undefined reference to `voprf_exp2_read'
/usr/bin/ld: libcrypto.a(x509_vfy.c.o): in function `reject_dns_name_in_common_name':
x509_vfy.c:(.text+0x16dc): undefined reference to `ASN1_STRING_to_UTF8'
/usr/bin/ld: libcrypto.a(x_name.c.o): in function `asn1_string_canon':
x_name.c:(.text+0xe94): undefined reference to `ASN1_STRING_to_UTF8'
/usr/bin/ld: libcrypto.a(v3_crld.c.o): in function `print_distpoint':
v3_crld.c:(.text+0x1304): undefined reference to `X509_NAME_print_ex'
/usr/bin/ld: libcrypto.a(v3_utl.c.o): in function `do_check_string':
v3_utl.c:(.text+0x288c): undefined reference to `ASN1_STRING_to_UTF8'
/usr/bin/ld: libcrypto.a(algorithm.c.o): in function `x509_digest_sign_algorithm':
algorithm.c:(.text+0xac): undefined reference to `x509_rsa_ctx_to_pss'
/usr/bin/ld: libcrypto.a(algorithm.c.o): in function `x509_digest_verify_init':
algorithm.c:(.text+0x2c4): undefined reference to `x509_rsa_pss_to_ctx'
/usr/bin/ld: libcrypto.a(v3_alt.c.o): in function `GENERAL_NAME_print':
v3_alt.c:(.text+0x7c4): undefined reference to `X509_NAME_print_ex'
/usr/bin/ld: libcrypto.a(t_x509.c.o): in function `X509_print_ex':
t_x509.c:(.text+0x404): undefined reference to `X509_NAME_print_ex'
/usr/bin/ld: t_x509.c:(.text+0x52c): undefined reference to `X509_NAME_print_ex'
/usr/bin/ld: libcrypto.a(t_x509.c.o): in function `X509_signature_print':
t_x509.c:(.text+0xb7c): undefined reference to `x509_print_rsa_pss_params'
collect2: error: ld returned 1 exit status
make[2]: *** [third_party/boringssl-with-bazel/CMakeFiles/bssl.dir/build.make:339: third_party/boringssl-with-bazel/bssl] Error 1
make[1]: *** [CMakeFiles/Makefile2:4800: third_party/boringssl-with-bazel/CMakeFiles/bssl.dir/all] Error 2
make: *** [Makefile:136: all] Error 2
Please help me to fix this problem.
Can you show what value the gRPC_SSL_PROVIDER variable has? If has module than you just init submodules and build with BoringSSL (see and see). Another option, you can build with OpenSSL, just set -DgRPC_SSL_PROVIDER=package.
I am fairly new to using Linux. But I believe I have done the correct steps to get set up:
wget for Python 3.8.5, did the make for it.
wget for boost 1.74, bootstrap, ./b2
And boost installed and setup everything except for Python which it did not auto-detect. After many hours of frustration, I can get it to find python with:
./bootstrap.sh --with-python=python3.8
running ./b2 --debug-configuration --with-python
shows that it has found it here:
notice: [python-cfg] Details of this Python configuration: notice:
[python-cfg] interpreter command: "/usr/local/bin/python3.8" notice:
[python-cfg] include path: "/usr/local/include/python3.8" notice:
[python-cfg] library path: "/usr/local/lib/python3.8/config"
"/usr/local/lib"
So to this end I am compiling my program successfully with the boost include and python include folder mentioned from b2's debug output above. I am linking similarly with -lpython3.8 -lboost_python38 -lboost_system
All 3 are being found evidently as it does not complain about missing libraries.
Parser.o: In function `_Py_DECREF':
Parser.cpp:(.text+0x5b): undefined reference to `_Py_Dealloc'
Parser.o: In function `sections_to_html(std::__cxx11::list<DivSection, std::allocator<DivSection> > const&)':
Parser.cpp:(.text+0x1eb3): undefined reference to `PyUnicode_FromString'
Parser.cpp:(.text+0x1edf): undefined reference to `PyUnicode_FromString'
Parser.o: In function `PyInit_Parser':
Parser.cpp:(.text+0x245b): undefined reference to `boost::python::detail::init_module(PyModuleDef&, void (*)())'
Parser.o: In function `boost::python::type_info::name() const':
Parser.cpp:(.text._ZNK5boost6python9type_info4nameEv[_ZNK5boost6python9type_info4nameEv]+0x1f): undefined reference to `boost::python::detail::gcc_demangle(char const*)'
Parser.o: In function `boost::python::api::object::object()':
Parser.cpp:(.text._ZN5boost6python3api6objectC2Ev[_ZN5boost6python3api6objectC5Ev]+0x14): undefined reference to `_Py_NoneStruct'
Parser.o: In function `_object* boost::python::expect_non_null<_object>(_object*)':
Parser.cpp:(.text._ZN5boost6python15expect_non_nullI7_objectEEPT_S4_[_ZN5boost6python15expect_non_nullI7_objectEEPT_S4_]+0x14): undefined reference to `boost::python::throw_error_already_set()'
Parser.o: In function `boost::python::tuple boost::python::make_tuple<boost::python::handle<_object>, boost::python::handle<_object> >(boost::python::handle<_object> const&, boost::python::handle<_object> const&)':
Parser.cpp:(.text._ZN5boost6python10make_tupleINS0_6handleI7_objectEES4_EENS0_5tupleERKT_RKT0_[_ZN5boost6python10make_tupleINS0_6handleI7_objectEES4_EENS0_5tupleERKT_RKT0_]+0x2c): undefined reference to `PyTuple_New'
Parser.cpp:(.text._ZN5boost6python10make_tupleINS0_6handleI7_objectEES4_EENS0_5tupleERKT_RKT0_[_ZN5boost6python10make_tupleINS0_6handleI7_objectEES4_EENS0_5tupleERKT_RKT0_]+0x51): undefined reference to `boost::python::api::object::object(boost::python::handle<_object> const&)'
Parser.cpp:(.text._ZN5boost6python10make_tupleINS0_6handleI7_objectEES4_EENS0_5tupleERKT_RKT0_[_ZN5boost6python10make_tupleINS0_6handleI7_objectEES4_EENS0_5tupleERKT_RKT0_]+0xda): undefined reference to `boost::python::api::object::object(boost::python::handle<_object> const&)'
Parser.o: In function `void boost::python::def<boost::python::tuple (*)(char const*)>(char const*, boost::python::tuple (*)(char const*))':
Parser.cpp:(.text._ZN5boost6python3defIPFNS0_5tupleEPKcEEEvS4_T_[_ZN5boost6python3defIPFNS0_5tupleEPKcEEEvS4_T_]+0x50): undefined reference to `boost::python::detail::scope_setattr_doc(char const*, boost::python::api::object const&, char const*)'
Parser.o: In function `boost::python::api::object boost::python::detail::make_function_aux<boost::python::tuple (*)(char const*), boost::python::default_call_policies, boost::mpl::vector2<boost::python::tuple, char const*> >(boost::python::tuple (*)(char const*), boost::python::default_call_policies const&, boost::mpl::vector2<boost::python::tuple, char const*> const&)':
Parser.cpp:(.text._ZN5boost6python6detail17make_function_auxIPFNS0_5tupleEPKcENS0_21default_call_policiesENS_3mpl7vector2IS3_S5_EEEENS0_3api6objectET_RKT0_RKT1_ [_ZN5boost6python6detail17make_function_auxIPFNS0_5tupleEPKcENS0_21default_call_policiesENS_3mpl7vector2IS3_S5_EEEENS0_3api6objectET_RKT0_RKT1_]+0x67): undefined reference to `boost::python::objects::function_object(boost::python::objects::py_function const&)'
Parser.o: In function `boost::python::objects::py_function_impl_base::py_function_impl_base()':
Parser.cpp:(.text._ZN5boost6python7objects21py_function_impl_baseC2Ev[_ZN5boost6python7objects21py_function_impl_baseC5Ev]+0xb): undefined reference to `vtable for boost::python::objects::py_function_impl_base'
Parser.o:(.data.rel.ro._ZTVN5boost6python7objects23caller_py_function_implINS0_6detail6callerIPFNS0_5tupleEPKcENS0_21default_call_policiesENS_3mpl7vector2IS5_S7_EEEEEE [_ZTVN5boost6python7objects23caller_py_function_implINS0_6detail6callerIPFNS0_5tupleEPKcENS0_21default_call_policiesENS_3mpl7vector2IS5_S7_EEEEEE]+0x30): undefined reference to `boost::python::objects::py_function_impl_base::max_arity() const'
Parser.o: In function `boost::python::objects::caller_py_function_impl<boost::python::detail::caller<boost::python::tuple (*)(char const*), boost::python::default_call_policies, boost::mpl::vector2<boost::python::tuple, char const*> > >::~caller_py_function_impl()':
Parser.cpp:(.text._ZN5boost6python7objects23caller_py_function_implINS0_6detail6callerIPFNS0_5tupleEPKcENS0_21default_call_policiesENS_3mpl7vector2IS5_S7_EEEEED2Ev [_ZN5boost6python7objects23caller_py_function_implINS0_6detail6callerIPFNS0_5tupleEPKcENS0_21default_call_policiesENS_3mpl7vector2IS5_S7_EEEEED5Ev]+0x22): undefined reference to `boost::python::objects::py_function_impl_base::~py_function_impl_base()'
Parser.o:(.data.rel.ro._ZTIN5boost6python7objects23caller_py_function_implINS0_6detail6callerIPFNS0_5tupleEPKcENS0_21default_call_policiesENS_3mpl7vector2IS5_S7_EEEEEE [_ZTIN5boost6python7objects23caller_py_function_implINS0_6detail6callerIPFNS0_5tupleEPKcENS0_21default_call_policiesENS_3mpl7vector2IS5_S7_EEEEEE]+0x10): undefined reference to `typeinfo for boost::python::objects::py_function_impl_base'
Parser.o: In function `boost::python::converter::pointer_arg_from_python<char const*>::pointer_arg_from_python(_object*)':
Parser.cpp:(.text._ZN5boost6python9converter23pointer_arg_from_pythonIPKcEC2EP7_object[_ZN5boost6python9converter23pointer_arg_from_pythonIPKcEC5EP7_object]+0x18): undefined reference to `_Py_NoneStruct'
Parser.cpp:(.text._ZN5boost6python9converter23pointer_arg_from_pythonIPKcEC2EP7_object[_ZN5boost6python9converter23pointer_arg_from_pythonIPKcEC5EP7_object]+0x34): undefined reference to `boost::python::converter::get_lvalue_from_python(_object*, boost::python::converter::registration const&)'
Parser.o: In function `boost::python::converter::pointer_arg_from_python<char const*>::operator()() const':
Parser.cpp:(.text._ZNK5boost6python9converter23pointer_arg_from_pythonIPKcEclEv[_ZNK5boost6python9converter23pointer_arg_from_pythonIPKcEclEv]+0x1e): undefined reference to `_Py_NoneStruct'
Parser.o: In function `boost::python::converter::expected_pytype_for_arg<boost::python::tuple>::get_pytype()':
Parser.cpp:(.text._ZN5boost6python9converter23expected_pytype_for_argINS0_5tupleEE10get_pytypeEv[_ZN5boost6python9converter23expected_pytype_for_argINS0_5tupleEE10get_pytypeEv]+0x1b): undefined reference to `boost::python::converter::registry::query(boost::python::type_info)'
Parser.cpp:(.text._ZN5boost6python9converter23expected_pytype_for_argINS0_5tupleEE10get_pytypeEv[_ZN5boost6python9converter23expected_pytype_for_argINS0_5tupleEE10get_pytypeEv]+0x32): undefined reference to `boost::python::converter::registration::expected_from_python_type() const'
Parser.o: In function `boost::python::converter::expected_pytype_for_arg<char const*>::get_pytype()':
Parser.cpp:(.text._ZN5boost6python9converter23expected_pytype_for_argIPKcE10get_pytypeEv[_ZN5boost6python9converter23expected_pytype_for_argIPKcE10get_pytypeEv]+0x1b): undefined reference to `boost::python::converter::registry::query(boost::python::type_info)'
Parser.cpp:(.text._ZN5boost6python9converter23expected_pytype_for_argIPKcE10get_pytypeEv[_ZN5boost6python9converter23expected_pytype_for_argIPKcE10get_pytypeEv]+0x32): undefined reference to `boost::python::converter::registration::expected_from_python_type() const'
Parser.o: In function `boost::python::converter::registration const& boost::python::converter::detail::registry_lookup2<char const volatile>(char const volatile& (*)())':
Parser.cpp:(.text._ZN5boost6python9converter6detail16registry_lookup2IVKcEERKNS1_12registrationEPFRT_vE[_ZN5boost6python9converter6detail16registry_lookup2IVKcEERKNS1_12registrationEPFRT_vE]+0x1f): undefined reference to `boost::python::converter::registry::lookup(boost::python::type_info)'
Parser.o: In function `boost::python::converter::pyobject_type<boost::python::tuple, &PyTuple_Type>::get_pytype()':
Parser.cpp:(.text._ZN5boost6python9converter13pyobject_typeINS0_5tupleEXadL_Z12PyTuple_TypeEEE10get_pytypeEv[_ZN5boost6python9converter13pyobject_typeINS0_5tupleEXadL_Z12PyTuple_TypeEEE10get_pytypeEv]+0x7): undefined reference to `PyTuple_Type'
collect2: error: ld returned 1 exit status
makefile:8: recipe for target 'Parser' failed
make: *** [Parser] Error 1
I see a bunch of boost namespace stuff coming up.
So this leads me to believe that either there is a change in the name mangling between what I've compiled and what is being linked in, or there is a difference with defines which is causing either namespace or other differences.
But I am unsure how to find out the cause, assuming I am correct with my previous assumptions.
EDIT: I had cut the dump short and said that 'most' of it seems to be from boost, but JaMiT called me on it. So theres the full dump.
EDIT 2: I checked my python config and the results are:
user#vm:/usr/local/lib/python3.8/config-3.8-x86_64-linux-gnu$ python python-config.py --cflags
-I/usr/local/include/python3.8 -I/usr/local/include/python3.8 -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall
user#vm:/usr/local/lib/python3.8/config-3.8-x86_64-linux-gnu$ python python-config.py --ldflags
-L/usr/local/lib/python3.8/config-3.8-x86_64-linux-gnu -lcrypt -lpthread -ldl -lutil -lm -lm
EDIT 3:
I used nm on libpython3.8.a from my /usr/local/lib/python3.8/config-3.8-x86_64-linux-gnu and found that PyUnicode_FromString and some others do appear correctly as type 'T' function-with-param.
So they are there.
Thanks to a comment by 'sehe' mentioning ordering of libs, I did some Google searching and found the problem - my linking step in the makefile was:
$(CC) $(COMMONFLAGS) $(LDFLAGS) $(LIBS) -o Parser Parser.o grammar.o words.o
The additional libraries I use should come at the end eg:
$(CC) $(COMMONFLAGS) $(LDFLAGS) -o Parser Parser.o grammar.o words.o $(LIBS)
But after fixing the aforementioned ordering of arguments on the linker invocation, I had additional undefined references crop up from within Python which had not been reported before.
This turned out not to be an issue as building an executable was just step one - making sure the code compiles and I can link.
In the end to get a makefile building a module I can import into Python, I needed to compile all cpp files with -fPIC and then link with -shared -export-dynamic
Python's lib was not needed and so my final libs are -lboost_python38 -lboost_system
After setting my LD_LIBRARY_PATH to point to the boost /stage/lib folder, I was able to import my Parser.so module and it worked correctly.
a C++ code built into a shared library for HELib is using NTL and GMP static library. But it gets following error:
/usr/bin/ld: /usr/local/lib/libntl.a(FFT.o): relocation R_X86_64_32 against `.rodata.str1.8' can not be used when making a shared object; recompile with -fPIC
/usr/local/lib/libntl.a: error adding symbols: Bad value
collect2: error: ld returned 1 exit status
It was suggested int the post Click here
to recompile NTL and GMP with "-fPIC " flags.
I'am not able to find how I should do that.
Edit:
I'm able to build the shared library now after :
recompiling GMP and NTL by:
./configure --enable-shared
for gmp and
./configure SHARED=on
After make Install of HELib. I get error when I run the example codes.
The link to the Makefile : click to see makefile
Error:
g++ -g -O2 -std=c++11 -pthread -DFHE_THREADS -DFHE_BOOT_THREADS -DFHE_DCRT_THREADS -o Test_General_x Test_General.cpp -L/usr/local/lib -lntl -lgmp -lm -lfhe
/usr/local/lib/libfhe.so: undefined reference to write_raw_int(std::ostream&, long, long)'
/usr/local/lib/libfhe.so: undefined reference toread_raw_ZZ(std::istream&, NTL::ZZ&)'
/usr/local/lib/libfhe.so: undefined reference to void write_raw_vector<long>(std::ostream&, std::vector<long, std::allocator<long> > const&)'
/usr/local/lib/libfhe.so: undefined reference towriteEyeCatcher(std::ostream&, char const*)'
/usr/local/lib/libfhe.so: undefined reference to write_raw_xdouble(std::ostream&, NTL::xdouble)'
/usr/local/lib/libfhe.so: undefined reference toread_ntl_vec_long(std::istream&, NTL::Vec&)'
/usr/local/lib/libfhe.so: undefined reference to void read_raw_vector<long>(std::istream&, std::vector<long, std::allocator<long> >&)'
/usr/local/lib/libfhe.so: undefined reference toreadEyeCatcher(std::istream&, char const*)'
/usr/local/lib/libfhe.so: undefined reference to read_raw_int(std::istream&, long)'
/usr/local/lib/libfhe.so: undefined reference toread_raw_xdouble(std::istream&)'
/usr/local/lib/libfhe.so: undefined reference to write_raw_ZZ(std::ostream&, NTL::ZZ const&)'
/usr/local/lib/libfhe.so: undefined reference towrite_ntl_vec_long(std::ostream&, NTL::Vec const&, long)'
collect2: error: ld returned 1 exit status
Makefile:179: recipe for target 'Test_General_x' failed
make: *** [Test_General_x] Error 1
For NTL v11.5.1 atleast, doing ./configure --help | grep -i pic (as suggested in one of the comments for GMP) did not help at all - it found no matches. However, making a one line change in the file ntl-11.5.1/src/DoConfig (on line 17) from:
'CXXFLAGS' => '-g -O2'
to:
'CXXFLAGS' => '-g -O2 -fPIC',
solved the problem for me.
Marc Glisse provided the answer for the first two parts of the question.For the third part "Undefined Reference error" the answer is I'd not compiled and linked a x.cpp containing the functions that caused the undefined reference into my shared library. hence check : nm -CD /usr/local/lib/libfhe.so to see if these functions are listed with a linking address or not. If not then check which code provides this functionality. Link that code to the shared library.
I'm trying to run some example code from this repository
When going to the example folder (/binacpp/example) and run i.e.
./example.run.sh
It works.
However when I update the file (even with just an extra space in a comment) and try to recompile the program by typing:
make example
Then I get this error:
Making example
g++ -I../lib/libcurl-7.56.0/include -I../lib/jsoncpp-1.8.3/include -I../lib/libwebsockets-2.4.0/include -I../lib/libbinacpp/include \
example.cpp \
-L../lib/libcurl-7.56.0/lib \
-L../lib/libwebsockets-2.4.0/lib \
-L../lib/libbinacpp/lib \
-lcurl -lcrypto -lwebsockets -lbinacpp -o example
/tmp/ccCycCcN.o: In function `ws_depth_onData(Json::Value&)':
example.cpp:(.text+0xd85): undefined reference to `Json::Value::asString[abi:cxx11]() const'
example.cpp:(.text+0xdf0): undefined reference to `Json::Value::asString[abi:cxx11]() const'
example.cpp:(.text+0xf79): undefined reference to `Json::Value::asString[abi:cxx11]() const'
example.cpp:(.text+0xfe4): undefined reference to `Json::Value::asString[abi:cxx11]() const'
/tmp/ccCycCcN.o: In function `ws_klines_onData(Json::Value&)':
example.cpp:(.text+0x1255): undefined reference to `Json::Value::asString[abi:cxx11]() const'
/tmp/ccCycCcN.o:example.cpp:(.text+0x1317): more undefined references to `Json::Value::asString[abi:cxx11]() const' follow
/tmp/ccCycCcN.o: In function `main':
example.cpp:(.text+0x22c4): undefined reference to `BinaCPP::init(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&)'
example.cpp:(.text+0x242d): undefined reference to `Json::Value::asString[abi:cxx11]() const'
example.cpp:(.text+0x24aa): undefined reference to `Json::Value::asString[abi:cxx11]() const'
example.cpp:(.text+0x25e5): undefined reference to `Json::Value::asString[abi:cxx11]() const'
example.cpp:(.text+0x2659): undefined reference to `Json::Value::asString[abi:cxx11]() const'
example.cpp:(.text+0x27d2): undefined reference to `Json::Value::asString[abi:cxx11]() const'
/tmp/ccCycCcN.o:example.cpp:(.text+0x28a2): more undefined references to `Json::Value::asString[abi:cxx11]() const' follow
collect2: error: ld returned 1 exit status
Makefile:25: recipe for target 'example' failed
make: *** [example] Error 1
I looked this error up and I'm guessing this is a linker error like described in this post. However I'm coming from Python and new to C++ and just don't see what is wrong. I see that the .h files are included and in
binacpp_websocket.h
I see
typedef int (*CB)(Json::Value &json_value );
Why am I getting the error?
NOTE: When trying to run the command "make example" I got the error:
Making example
g++ -I../lib/libcurl-7.56.0/include -I../lib/jsoncpp-1.8.3/include -I../lib/libwebsockets-2.4.0/include -I../lib/libbinacpp/include \
example.cpp \
-L../lib/libcurl-7.56.0/lib \
-L../lib/libwebsockets-2.4.0/lib \
-L../lib/libbinacpp/lib \
-lcurl -ljsoncpp -lcrypto -lwebsockets -lbinacpp -o example
/usr/bin/ld: cannot find -ljsoncpp
collect2: error: ld returned 1 exit status
Makefile:25: recipe for target 'example' failed
make: *** [example] Error 1
Somewhere in the repo (I cannot find it now) it said that "-ljsoncpp" shouldn't be there. After removing this the compiler did run but it gave the linker error.
I have the source .h and .c files for libmodbus (http://libmodbus.org/releases/libmodbus-3.0.6.tar.gz). I dumped them into my Qt Project after learning that Qt is smart enough to know the difference b/w c and c++ files.
I include modbus.h in main.cpp and I get about 50 errors (most of which are undefined reference errors). Note I did get libmodbus working in ubuntu using codeblocks and it was communicating fine. I'm trying this in windows now and both Qt and codeblocks seem to be angry at me.
Here is my .pro file.
QT += core
QT += widgets
QT -= gui
TARGET = testModBus
CONFIG += console
CONFIG -= app_bundle
TEMPLATE = app
QMAKE_CXXFLAGS += -w
QMAKE_CFLAGS += -w
SOURCES += main.cpp \
modbus.c \
modbus-data.c \
modbus-rtu.c \
modbus-tcp.c
HEADERS += \
config.h \
modbus.h \
modbus-private.h \
modbus-rtu.h \
modbus-rtu-private.h \
modbus-tcp.h \
modbus-tcp-private.h \
modbus-version.h \
zModBus.h \
inttypes.h \
stdint.h
And here is my Qt Output when I try to Compile:
18:03:02: Starting: "E:\Qt\Tools\mingw48_32\bin\mingw32-make.exe"
E:\Qt\5.2.1\mingw48_32\bin\qmake.exe -spec win32-g++ -o Makefile ..\testModBus\testModBus.pro
E:/Qt/Tools/mingw48_32/bin/mingw32-make -f Makefile.Release
mingw32-make[1]: Entering directory 'C:/Users/SSK/Desktop/qtProjects/build-testModBus-Desktop_Qt_5_2_1_MinGW_32bit-Release'
g++ -Wl,-s -Wl,-subsystem,console -mthreads -o release\testModBus.exe release/main.o release/modbus.o release/modbus-data.o release/modbus-rtu.o release/modbus-tcp.o -lglu32 -lopengl32 -lgdi32 -luser32 -LE:\Qt\5.2.1\mingw48_32\lib -lQt5Widgets -lQt5Gui -lQt5Core
release/modbus-tcp.o:modbus-tcp.c:(.text+0x24f): undefined reference to `_imp__select#20'
release/modbus-tcp.o:modbus-tcp.c:(.text+0x2a3): undefined reference to `_imp__recv#16'
release/modbus-tcp.o:modbus-tcp.c:(.text+0x2d7): undefined reference to `_imp__recv#16'
release/modbus-tcp.o:modbus-tcp.c:(.text+0x30d): undefined reference to `_imp__shutdown#8'
release/modbus-tcp.o:modbus-tcp.c:(.text+0x31c): undefined reference to `_imp__closesocket#4'
Makefile.Release:85: recipe for target 'release\testModBus.exe' failed
release/modbus-tcp.o:modbus-tcp.c:(.text+0x363): undefined reference to `_imp__setsockopt#20'
release/modbus-tcp.o:modbus-tcp.c:(.text+0x394): undefined reference to `_imp__ioctlsocket#12'
release/modbus-tcp.o:modbus-tcp.c:(.text+0x3c6): undefined reference to `_imp__connect#12'
mingw32-make[1]: Leaving directory 'C:/Users/SSK/Desktop/qtProjects/build-testModBus-Desktop_Qt_5_2_1_MinGW_32bit-Release'
makefile:34: recipe for target 'release' failed
release/modbus-tcp.o:modbus-tcp.c:(.text+0x3e2): undefined reference to `_imp__WSAGetLastError#0'
release/modbus-tcp.o:modbus-tcp.c:(.text+0x444): undefined reference to `_imp__select#20'
release/modbus-tcp.o:modbus-tcp.c:(.text+0x47f): undefined reference to `_imp__getsockopt#20'
release/modbus-tcp.o:modbus-tcp.c:(.text+0x517): undefined reference to `_imp__send#16'
release/modbus-tcp.o:modbus-tcp.c:(.text+0x597): undefined reference to `_imp__WSAStartup#8'
release/modbus-tcp.o:modbus-tcp.c:(.text+0x624): undefined reference to `_imp__socket#12'
release/modbus-tcp.o:modbus-tcp.c:(.text+0x65e): undefined reference to `_imp__htons#4'
release/modbus-tcp.o:modbus-tcp.c:(.text+0x66f): undefined reference to `_imp__inet_addr#4'
release/modbus-tcp.o:modbus-tcp.c:(.text+0x6c8): undefined reference to `_imp__closesocket#4'
release/modbus-tcp.o:modbus-tcp.c:(.text+0x74c): undefined reference to `_imp__getaddrinfo#16'
release/modbus-tcp.o:modbus-tcp.c:(.text+0x780): undefined reference to `_imp__socket#12'
release/modbus-tcp.o:modbus-tcp.c:(.text+0x7bb): undefined reference to `_imp__freeaddrinfo#4'
release/modbus-tcp.o:modbus-tcp.c:(.text+0x7d5): undefined reference to `_imp__closesocket#4'
release/modbus-tcp.o:modbus-tcp.c:(.text+0x82f): undefined reference to `gai_strerrorW'
release/modbus-tcp.o:modbus-tcp.c:(.text+0x8bc): undefined reference to `_imp__select#20'
release/modbus-tcp.o:modbus-tcp.c:(.text+0x96c): undefined reference to `_imp__socket#12'
release/modbus-tcp.o:modbus-tcp.c:(.text+0x9ab): undefined reference to `_imp__setsockopt#20'
release/modbus-tcp.o:modbus-tcp.c:(.text+0x9f0): undefined reference to `_imp__htons#4'
release/modbus-tcp.o:modbus-tcp.c:(.text+0xa0a): undefined reference to `_imp__inet_addr#4'
release/modbus-tcp.o:modbus-tcp.c:(.text+0xa2a): undefined reference to `_imp__bind#12'
release/modbus-tcp.o:modbus-tcp.c:(.text+0xa45): undefined reference to `_imp__listen#8'
release/modbus-tcp.o:modbus-tcp.c:(.text+0xa69): undefined reference to `_imp__htonl#4'
release/modbus-tcp.o:modbus-tcp.c:(.text+0xa85): undefined reference to `_imp__closesocket#4'
release/modbus-tcp.o:modbus-tcp.c:(.text+0xb38): undefined reference to `_imp__getaddrinfo#16'
release/modbus-tcp.o:modbus-tcp.c:(.text+0xb89): undefined reference to `_imp__setsockopt#20'
release/modbus-tcp.o:modbus-tcp.c:(.text+0xb99): undefined reference to `_imp__closesocket#4'
release/modbus-tcp.o:modbus-tcp.c:(.text+0xbc8): undefined reference to `_imp__socket#12'
release/modbus-tcp.o:modbus-tcp.c:(.text+0xbf9): undefined reference to `_imp__freeaddrinfo#4'
release/modbus-tcp.o:modbus-tcp.c:(.text+0xc23): undefined reference to `_imp__bind#12'
release/modbus-tcp.o:modbus-tcp.c:(.text+0xc33): undefined reference to `_imp__closesocket#4'
release/modbus-tcp.o:modbus-tcp.c:(.text+0xc63): undefined reference to `_imp__listen#8'
release/modbus-tcp.o:modbus-tcp.c:(.text+0xc77): undefined reference to `_imp__freeaddrinfo#4'
release/modbus-tcp.o:modbus-tcp.c:(.text+0xca5): undefined reference to `_imp__closesocket#4'
release/modbus-tcp.o:modbus-tcp.c:(.text+0xcda): undefined reference to `gai_strerrorW'
release/modbus-tcp.o:modbus-tcp.c:(.text+0xd61): undefined reference to `_imp__accept#12'
release/modbus-tcp.o:modbus-tcp.c:(.text+0xd8b): undefined reference to `_imp__inet_ntoa#4'
release/modbus-tcp.o:modbus-tcp.c:(.text+0xdc8): undefined reference to `_imp__closesocket#4'
release/modbus-tcp.o:modbus-tcp.c:(.text+0xe19): undefined reference to `_imp__accept#12'
release/modbus-tcp.o:modbus-tcp.c:(.text+0xe57): undefined reference to `_imp__closesocket#4'
e:/qt/tools/mingw48_32/bin/../lib/gcc/i686-w64-mingw32/4.8.0/../../../../i686-w64-mingw32/bin/ld.exe: release/modbus-tcp.o: bad reloc address 0x250 in section `.rdata'
e:/qt/tools/mingw48_32/bin/../lib/gcc/i686-w64-mingw32/4.8.0/../../../../i686-w64-mingw32/bin/ld.exe: final link failed: Invalid operation
collect2.exe: error: ld returned 1 exit status
mingw32-make[1]: *** [release\testModBus.exe] Error 1
mingw32-make: *** [release] Error 2
18:03:04: The process "E:\Qt\Tools\mingw48_32\bin\mingw32-make.exe" exited with code 2.
You need to include ws2_32.lib in your dependencies. I.e. in your *.pro file add the line:
LIBS += -lws2_32
Turns out that the error was generated because of __declspec(dllexport) in one of the header files. Removed that and it went away. Then it started throwing a new error which is where I'm currently stuck at.