I am trying to build the example provided by dlib for multiple class SVM training using QT on windows. (the example is available at this link: http://dlib.net/multiclass_classification_ex.cpp.html)
first of all I took the DLIB .lib files from a prebuilt library using MS visual studio, and took the include files and modified the QT .pro file to be as follows.
QT -= gui
CONFIG += c++11 console
CONFIG -= app_bundle
DEFINES += QT_DEPRECATED_WARNINGS
SOURCES += main.cpp
INCLUDEPATH += $$PWD/dlib/include
debug {
LIBS += -L$$PWD/dlib/lib -ldlib_debug_64bit_msvc1900
}
!debug {
LIBS += -L$$PWD/dlib/lib -ldlib_release_64bit_msvc1900
}
when i try building the code i get the following errors:
C:\Users\Administrator\Documents\SVMDlib\main.cpp:-1: error: undefined reference to `dlib::thread_pool_implementation::~thread_pool_implementation()'
C:\Users\Administrator\Documents\SVMDlib\main.cpp:-1: error: undefined reference to `dlib::thread_pool_implementation::shutdown_pool()'
C:\Users\Administrator\Documents\SVMDlib\main.cpp:-1: error: undefined reference to `dlib::thread_pool_implementation::thread_pool_implementation(unsigned long)'
C:\Users\Administrator\Documents\SVMDlib\main.cpp:-1: error: undefined reference to `dlib::thread_pool_implementation::num_threads_in_pool() const'
C:\Users\Administrator\Documents\SVMDlib\main.cpp:-1: error: undefined reference to `dlib::thread_pool_implementation::num_threads_in_pool() const'
C:\Users\Administrator\Documents\SVMDlib\main.cpp:-1: error: undefined reference to `dlib::thread_pool_implementation::find_empty_task_slot() const'
C:\Users\Administrator\Documents\SVMDlib\main.cpp:-1: error: undefined reference to `dlib::thread_pool_implementation::make_next_task_id(long)'
C:\Users\Administrator\Documents\SVMDlib\main.cpp:-1: error: undefined reference to `dlib::thread_pool_implementation::wait_for_all_tasks() const'
C:\Users\Administrator\Documents\SVMDlib\main.cpp:-1: error: undefined reference to `dlib::thread_pool_implementation::is_worker_thread(unsigned long) const'
C:\Users\Administrator\Documents\SVMDlib\main.cpp:-1: error: undefined reference to `dlib::thread_pool_implementation::find_empty_task_slot() const'
C:\Users\Administrator\Documents\SVMDlib\main.cpp:-1: error: undefined reference to `dlib::thread_pool_implementation::~thread_pool_implementation()'
collect2.exe:-1: error: error: ld returned 1 exit status
knowing that i tried to run the simple SVM code (provided here: http://dlib.net/svm_ex.cpp.html) it compiled and ran perfectly.
Am I missing a library of some kind? as all the errors are linking error and undefined references?
Related
trying to pull and build Visqol following the instructions provided for Linux. I downloaded Bazel, everything seems fine. But when I try to execute with bazel build :visqol -c opt i get the following errors
bazel-out/k8-opt/bin/_objs/visqol/main.o:main.cc:function main: error: undefined reference to 'std::filesystem::__cxx11::path::_M_split_cmpts()'
bazel-out/k8-opt/bin/_objs/visqol/main.o:main.cc:function main: error: undefined reference to 'std::filesystem::status(std::filesystem::__cxx11::path const&)'
bazel-out/k8-opt/bin/_objs/visqol_lib/commandline_parser.o:commandline_parser.cc:function Visqol::VisqolCommandLineParser::FileExists(Visqol::FilePath const&): error: undefined reference to 'std::filesystem::__cxx11::path::_M_split_cmpts()'
bazel-out/k8-opt/bin/_objs/visqol_lib/commandline_parser.o:commandline_parser.cc:function Visqol::VisqolCommandLineParser::FileExists(Visqol::FilePath const&): error: undefined reference to 'std::filesystem::status(std::filesystem::__cxx11::path const&)'
bazel-out/k8-opt/bin/_objs/visqol_lib/commandline_parser.o:commandline_parser.cc:function Visqol::VisqolCommandLineParser::ReadFilesToCompare(Visqol::FilePath const&): error: undefined reference to 'std::filesystem::__cxx11::path::_M_split_cmpts()'
bazel-out/k8-opt/bin/_objs/visqol_lib/commandline_parser.o:commandline_parser.cc:function Visqol::VisqolCommandLineParser::BuildFilePairPaths(Visqol::CommandLineArgs const&): error: undefined reference to 'std::filesystem::__cxx11::path::_M_split_cmpts()'
bazel-out/k8-opt/bin/_objs/visqol_lib/commandline_parser.o:commandline_parser.cc:function Visqol::VisqolCommandLineParser::BuildFilePairPaths(Visqol::CommandLineArgs const&): error: undefined reference to 'std::filesystem::status(std::filesystem::__cxx11::path const&)'
bazel-out/k8-opt/bin/_objs/visqol_lib/commandline_parser.o:commandline_parser.cc:function Visqol::VisqolCommandLineParser::BuildFilePairPaths(Visqol::CommandLineArgs const&): error: undefined reference to 'std::filesystem::status(std::filesystem::__cxx11::path const&)'
bazel-out/k8-opt/bin/_objs/visqol_lib/commandline_parser.o:commandline_parser.cc:function Visqol::VisqolCommandLineParser::Parse(int, char**): error: undefined reference to 'std::filesystem::current_path[abi:cxx11]()'
bazel-out/k8-opt/bin/_objs/visqol_lib/commandline_parser.o:commandline_parser.cc:function Visqol::VisqolCommandLineParser::Parse(int, char**): error: undefined reference to 'std::filesystem::current_path[abi:cxx11]()'
collect2: error: ld returned 1 exit status
I've seen similar issues in c++ on the web but most of these are building with make commands and solve this by adding the -lstdc++fs or LDLIBS=-lstdc++fs options. However, those are unrecognized for Bazel
I'm on Debian 10.13 and my Bazel version is 5.3.1, my c++ version seems to be 8.3.0
In accordance with how to use std::filesystem on gcc 8?, change the line build --linkopt=-ldl in .bazelrc into:
build --linkopt=-lstdc++fs -ldl
You could also open a ticket in the Visgol repo and tell them about this problem and get a proper solution in the future releases of Visgol.
I am new to qt. I am using qt creator successfully to create ui. I need bluetooth functionality from qt. I had earlier version of code running through terminal. I copy pasted the running code. I get a lot of undefined references.
error: undefined reference to str2ba'
error: undefined reference tosqlite3_open'
error: undefined reference to sqlite3_errmsg'
error: undefined reference tosqlite3_errmsg'
error: undefined reference to sqlite3_free'
error: undefined reference tosqlite3_close'
error: undefined reference to hci_get_route'
error: undefined reference tohci_open_dev'
error: undefined reference to hci_inquiry'
error: undefined reference toba2str'
error: undefined reference to hci_read_remote_name'
error: undefined reference toba2str'
Is there anything like linux apis can not be used in qt? how to integrate the app then? Or do I have to link libraries like -lpthread -lbluetooth etc.
"Undefined reference..." seems to be a linker error.
Do you link against libsqlite3 and libbluetooth?
Adding
-lsqplite3 -lbluetooth
to your ld/g++ command line helps in that case
I am writing a C++ application (based on Tensorflow Serving) in which I need to call Python and Numpy functions (from Python.h and numpy.h).
This application is built with Bazel.
So I include the header:
#include "tensorflow/python/lib/core/numpy.h"
which in turn includes Python.h.
This file seems to wrap numpy to fix an issue described in this Stack Overflow post.
Any other C++ code within the Tensorflow project which needs to make calls to Python.h also does not directly include it, but only includes tensorflow/python/lib/core/numpy.h. On the Bazel side, it seems to suffice to simply add //util/python:python_headers to the deps of the build.
My BUILD file looks like this:
...
cc_library(
name = "my_library",
srcs = ["my_library.cc"],
hdrs = ["my_library.h"],
deps = [
#org_tensorflow//util/python:python_headers",
#org_tensorflow//third_party/py/numpy:headers",
] + SOME_OTHER_DEPS + TENSORFLOW_DEPS + SUPPORTED_TENSORFLOW_OPS,
)
cc_binary(
name = "my_main",
srcs = ["my_main.cc"],
deps = [":my_library"],
)
...
Building the library with bazel build :my_library works fine.
Building the binary the same way does not work, I get the following errors:
bazel-out/local-fastbuild/bin/servable/_objs/my_library/servable/my:library.pic.o:my_library.cc:function tensorflow::serving::NumpyInitializer::init(): error: undefined reference to 'Py_Initialize'
bazel-out/local-fastbuild/bin/external/org_tensorflow/tensorflow/python/_objs/py_func_lib/external/org_tensorflow/tensorflow/python/lib/core/py_func.pic.o:py_func.cc:function tensorflow::(anonymous namespace)::MakeArgTuple(tensorflow::(anonymous namespace)::PyCall*, _object**): error: undefined reference to 'PyList_New'
bazel-out/local-fastbuild/bin/external/org_tensorflow/tensorflow/python/_objs/py_func_lib/external/org_tensorflow/tensorflow/python/lib/core/py_func.pic.o:py_func.cc:function tensorflow::(anonymous namespace)::MakeArgTuple(tensorflow::(anonymous namespace)::PyCall*, _object**): error: undefined reference to 'PyList_SetItem'
bazel-out/local-fastbuild/bin/external/org_tensorflow/tensorflow/python/_objs/py_func_lib/external/org_tensorflow/tensorflow/python/lib/core/py_func.pic.o:py_func.cc:function tensorflow::(anonymous namespace)::MakeArgTuple(tensorflow::(anonymous namespace)::PyCall*, _object**): error: undefined reference to 'Py_BuildValue'
bazel-out/local-fastbuild/bin/external/org_tensorflow/tensorflow/python/_objs/py_func_lib/external/org_tensorflow/tensorflow/python/lib/core/py_func.pic.o:py_func.cc:function tensorflow::(anonymous namespace)::IsSingleNone(_object*): error: undefined reference to 'PyType_IsSubtype'
bazel-out/local-fastbuild/bin/external/org_tensorflow/tensorflow/python/_objs/py_func_lib/external/org_tensorflow/tensorflow/python/lib/core/py_func.pic.o:py_func.cc:function tensorflow::(anonymous namespace)::IsSingleNone(_object*): error: undefined reference to '_Py_NoneStruct'
bazel-out/local-fastbuild/bin/external/org_tensorflow/tensorflow/python/_objs/py_func_lib/external/org_tensorflow/tensorflow/python/lib/core/py_func.pic.o:py_func.cc:function tensorflow::(anonymous namespace)::DoCallPyFunc(tensorflow::(anonymous namespace)::PyCall*): error: undefined reference to 'PyEval_CallObjectWithKeywords'
bazel-out/local-fastbuild/bin/external/org_tensorflow/tensorflow/python/_objs/py_func_lib/external/org_tensorflow/tensorflow/python/lib/core/py_func.pic.o:py_func.cc:function tensorflow::(anonymous namespace)::DoCallPyFunc(tensorflow::(anonymous namespace)::PyCall*): error: undefined reference to 'PyErr_Occurred'
bazel-out/local-fastbuild/bin/external/org_tensorflow/tensorflow/python/_objs/py_func_lib/external/org_tensorflow/tensorflow/python/lib/core/py_func.pic.o:py_func.cc:function tensorflow::(anonymous namespace)::DoCallPyFunc(tensorflow::(anonymous namespace)::PyCall*): error: undefined reference to 'PyErr_Print'
bazel-out/local-fastbuild/bin/external/org_tensorflow/tensorflow/python/_objs/py_func_lib/external/org_tensorflow/tensorflow/python/lib/core/py_func.pic.o:py_func.cc:function tensorflow::(anonymous namespace)::DoCallPyFunc(tensorflow::(anonymous namespace)::PyCall*): error: undefined reference to 'PyList_Size'
bazel-out/local-fastbuild/bin/external/org_tensorflow/tensorflow/python/_objs/py_func_lib/external/org_tensorflow/tensorflow/python/lib/core/py_func.pic.o:py_func.cc:function tensorflow::(anonymous namespace)::DoCallPyFunc(tensorflow::(anonymous namespace)::PyCall*): error: undefined reference to 'PyList_GetItem'
bazel-out/local-fastbuild/bin/external/org_tensorflow/tensorflow/python/_objs/py_func_lib/external/org_tensorflow/tensorflow/python/lib/core/py_func.pic.o:py_func.cc:function tensorflow::(anonymous namespace)::DoCallPyFunc(tensorflow::(anonymous namespace)::PyCall*): error: undefined reference to 'PyType_IsSubtype'
bazel-out/local-fastbuild/bin/external/org_tensorflow/tensorflow/python/_objs/py_func_lib/external/org_tensorflow/tensorflow/python/lib/core/py_func.pic.o:py_func.cc:function tensorflow::ConvertNdarrayToTensor(_object*, tensorflow::Tensor*): error: undefined reference to 'PyString_AsStringAndSize'
bazel-out/local-fastbuild/bin/external/org_tensorflow/tensorflow/python/_objs/py_func_lib/external/org_tensorflow/tensorflow/python/lib/core/py_func.pic.o:py_func.cc:function tensorflow::ConvertTensorToNdarray(tensorflow::Tensor const&, _object**): error: undefined reference to 'PyString_FromStringAndSize'
bazel-out/local-fastbuild/bin/external/org_tensorflow/tensorflow/python/_objs/py_func_lib/external/org_tensorflow/tensorflow/python/lib/core/py_func.pic.o:py_func.cc:function tensorflow::PyFuncOp::Compute(tensorflow::OpKernelContext*): error: undefined reference to 'PyGILState_Ensure'
bazel-out/local-fastbuild/bin/external/org_tensorflow/tensorflow/python/_objs/py_func_lib/external/org_tensorflow/tensorflow/python/lib/core/py_func.pic.o:py_func.cc:function tensorflow::PyFuncOp::Compute(tensorflow::OpKernelContext*): error: undefined reference to 'PyGILState_Release'
bazel-out/local-fastbuild/bin/external/org_tensorflow/tensorflow/python/_objs/numpy_lib/external/org_tensorflow/tensorflow/python/lib/core/numpy.pic.o:numpy.cc:function _import_array: error: undefined reference to 'PyImport_ImportModule'
bazel-out/local-fastbuild/bin/external/org_tensorflow/tensorflow/python/_objs/numpy_lib/external/org_tensorflow/tensorflow/python/lib/core/numpy.pic.o:numpy.cc:function _import_array: error: undefined reference to 'PyExc_ImportError'
bazel-out/local-fastbuild/bin/external/org_tensorflow/tensorflow/python/_objs/numpy_lib/external/org_tensorflow/tensorflow/python/lib/core/numpy.pic.o:numpy.cc:function _import_array: error: undefined reference to 'PyErr_SetString'
So there is obviously linking errors against Python.h. However, compiling any Tensorflow-internal goals works fine. I find it weird that it now can not link to Python.h even inside Tensorflow files.
After spending a few days looking into Tensorflow and their BUILD files I am out of ideas how to make this work.
So now I ask here: where and how exactly is the correct inclusion of Python defined in Tensorflow (and its Bazel files?).
Some clues seem to be in the definitions in util/python/BUILD and tensorflow/tensorflow.bzl.
There seems to be quite a bit of Bazel magic going on there.
You need to link your executable against libpython.(a|so). Your compile actions correctly made use of python.h and put some undefined symbols into objects. When building executable, linking action needs to resolve all undefined symbols, so it's no longer enough to have python.h, you need "python.cc".
My knowledge of tensorflow is rather poor, maybe somebody from the team can comment further if your use case is a solved problem. For general Bazel solution to "How to provide libpython" I'd recommend external repositories and their rules. I think this email thread will get you almost to the end.
Or you can copy the library over into your workspace and put it as a src to cc_binary rule.
These are the errors that I'm getting while building the c++ project in QT Creator:
error: undefined reference to `leveldb::DestroyDB(std::string const&, leveldb::Options const&)'
error: undefined reference to `leveldb::RepairDB(std::string const&, leveldb::Options const&)'
error: undefined reference to `leveldb::DB::Open(leveldb::Options const&, std::string const&, leveldb::DB**)'
error: undefined reference to `leveldb::Status::ToString() const'
Earlier, additionally, I was getting tens of similar libcurl undefined reference errors, but I fixed the errors after using the "add library" and selecting the "System Library" option, which automatically included the following line to the .pro file:
unix|win32: LIBS += -lcurl
So, I tried the same thing for leveldb, which has automatically included the following line in the .pro file:
unix|win32: LIBS += -lleveldb
But despite that, the errors are still there.
I am trying to embed python in c++. I am not able to compile some c++ code that uses Python.h. I get an error that seems to be the library is not referenced correctly.
Below is the error shown which I received:
/tmp/ccxiQ8eE.o:(.data+0xc4): undefined reference to Py_NoopCmd(_object*, _object*)'
/tmp/ccxiQ8eE.o:(.data+0xd4): undefined reference toPy_FilterPalletteCmd(_object*, _object*)'
/tmp/ccxiQ8eE.o:(.data+0xe4): undefined reference to Py_FilterCmd(_object*, _object*)'
/tmp/ccxiQ8eE.o:(.data+0xf4): undefined reference toPy_CaptureCmd(_object*, _object*)'
/tmp/ccxiQ8eE.o:(.data+0x104): undefined reference to Py_CaptureBufferCmd(_object*, _object*)'
/tmp/ccxiQ8eE.o:(.data+0x114): undefined reference toPy_StreamCmd(_object*, _object*)'
/tmp/ccxiQ8eE.o:(.data+0x1b4): undefined reference to Py_ModelDebugCmd(_object*, _object*)'
/tmp/ccxiQ8eE.o:(.data+0x1c4): undefined reference toPy_ModelVersionCmd(_object*, _object*)'
/tmp/ccxiQ8eE.o:(.data+0x1d4): undefined reference to Py_ModelSimRunCmd(_object*, _object*)'
/tmp/ccxiQ8eE.o:(.data+0x1e4): undefined reference toPy_ModelSimEndCmd(_object*, _object*)'
collect2: error: ld returned 1 exit status
make: *** [xgs_sim.linux] Error 1
For these functions prototype declaration has been done in some other test.h file and that file has been included while compiling in the program.cc file.
The function definition has been done in test.cc file.
Python version used is python 2.7.1.
Any help/guidelines will be much appreciated. Thanks.