Catch fails on simple example - c++

I am trying to integrate Catch unit testing to my project but it fails for the currently available
Catch v1.10.0
Generated: 2017-08-26 15:16:46.676990
Example:
test.cpp
#include "catch.hpp"
#define CATCH_CONFIG_MAIN
TEST_CASE("CATCH TEST"){
REQUIRE(1 == 1);
}
g++ test.cpp -o test.exe -std=c++11
Error:
Undefined symbols for architecture x86_64:
"Catch::ResultBuilder::endExpression(Catch::DecomposedExpression const&)", referenced from:
Catch::BinaryExpression<int const&, (Catch::Internal::Operator)0, int const&>::endExpression() const in test-b77427.o
"Catch::ResultBuilder::setResultType(bool)", referenced from:
Catch::BinaryExpression<int const&, (Catch::Internal::Operator)0, int const&>::endExpression() const in test-b77427.o
"Catch::ResultBuilder::useActiveException(Catch::ResultDisposition::Flags)", referenced from:
____C_A_T_C_H____T_E_S_T____0() in test-b77427.o
"Catch::ResultBuilder::react()", referenced from:
____C_A_T_C_H____T_E_S_T____0() in test-b77427.o
"Catch::ResultBuilder::ResultBuilder(char const*, Catch::SourceLineInfo const&, char const*, Catch::ResultDisposition::Flags, char const*)", referenced from:
____C_A_T_C_H____T_E_S_T____0() in test-b77427.o
"Catch::ResultBuilder::~ResultBuilder()", referenced from:
____C_A_T_C_H____T_E_S_T____0() in test-b77427.o
"Catch::SourceLineInfo::SourceLineInfo(char const*, unsigned long)", referenced from:
____C_A_T_C_H____T_E_S_T____0() in test-b77427.o
___cxx_global_var_init in test-b77427.o
"Catch::isDebuggerActive()", referenced from:
____C_A_T_C_H____T_E_S_T____0() in test-b77427.o
"Catch::AutoReg::AutoReg(void (*)(), Catch::SourceLineInfo const&, Catch::NameAndDesc const&)", referenced from:
___cxx_global_var_init in test-b77427.o
"Catch::AutoReg::~AutoReg()", referenced from:
___cxx_global_var_init in test-b77427.o
"Catch::toString(int)", referenced from:
Catch::ExpressionLhs<int const&>::reconstructExpression(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >&) const in test-b77427.o
Catch::BinaryExpression<int const&, (Catch::Internal::Operator)0, int const&>::reconstructExpression(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >&) const in test-b77427.o
"Catch::ResultBuilder::shouldDebugBreak() const", referenced from:
____C_A_T_C_H____T_E_S_T____0() in test-b77427.o
"_main", referenced from:
implicit entry/start for main executable
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit
g++ --version
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/usr/include/c++/4.2.1
Apple LLVM version 8.1.0 (clang-802.0.42)
Target: x86_64-apple-darwin16.7.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin

As it stands your program does not have a main function. If you compile it, the linker will complain about the absence of a main function. Since you are writing unit tests using the catch framework, you want that framework to generate a main function for you.
The catch framework looks whether CATCH_CONFIG_MAIN is defined and if yes, it generates a main function for you which runs all the tests you define. Because compilation is a linear process, the macro CATCH_CONFIG_MAIN has to be defined before including catch.hpp. Otherwise, the library will never “see” this macro.
#define CATCH_CONFIG_MAIN
#include "catch.hpp"
TEST_CASE("CATCH TEST"){
REQUIRE(1 == 1);
}
Live example

Related

openvino on macOS build issue

I followed the instruction on thier github https://github.com/openvinotoolkit/openvino to build it on macOS, done it and when i wrote a small code to check was all clear or not
#include <string>
#include <iostream>
#include <dlfcn.h>
#include <fstream>
#define USE_STATIC_IE
#define _CRT_SECURE_NO_WARNINGS
#include <ie_core.hpp>
using namespace :: std;
int main(){
dlopen("/Users/nk/Documents/HZ/openvino/inference-engine/temp/tbb/lib/libtbb.dylib", RTLD_LAZY);
dlopen("/Users/nk/Documents/HZ/openvino/bin/intel64/Release/lib/libngraph.dylib", RTLD_LAZY);
dlopen("/Users/nk/Documents/HZ/openvino/bin/intel64/Release/lib/libinference_engine_transformations.dylib", RTLD_LAZY);
dlopen("/Users/nk/Documents/HZ/openvino/bin/intel64/Release/lib/libinference_engine_legacy.dylib", RTLD_LAZY);
dlopen("/Users/nk/Documents/HZ/openvino/bin/intel64/Release/lib/libinference_engine.dylib", RTLD_LAZY);
dlopen("/Users/nk/Documents/HZ/openvino/bin/intel64/Release/lib/libinference_engine_lp_transformations.dylib", RTLD_LAZY);
dlopen("/Users/nk/Documents/HZ/openvino/bin/intel64/Release/lib/libMKLDNNPlugin.dylib", RTLD_LAZY);
const std::string pluginsFilePath = "/Users/nk/Documents/HZ/openvino/bin/intel64/Release/lib/plugins.xml";
InferenceEngine::Core ie(pluginsFilePath);
const auto info = ie.GetVersions("CPU");
if(!info.empty())
cout << "Yes";
return 0;
}
when i compile it with command
g++ -std=c++11 -I/Users/nk/Documents/HZ/openvino/inference-engine/include testdll.cpp -o testdll && "/Users/nk/Documents/FelenaSoft/"testdll
it gave me the error
Undefined symbols for architecture x86_64:
"InferenceEngine::Core::Core(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)", referenced from:
_main in testdll-788073.o
"InferenceEngine::Core::GetVersions(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) const", referenced from:
_main in testdll-788073.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
then i added .a libs and ran this command
g++ -std=c++11 -L/Users/nk/Documents/HZ/openvino/bin/intel64/Release/lib -lmkldnn -lpugixml -linference_engine_s -I/Users/nk/Documents/HZ/openvino/inference-engine/include testdll.cpp -o testdll && "/Users/nk/Documents/FelenaSoft/"testdll
and i got this
Undefined symbols for architecture x86_64:
"ngraph::as_output_vector(std::__1::vector<std::__1::shared_ptr<ngraph::Node>, std::__1::allocator<std::__1::shared_ptr<ngraph::Node> > > const&)", referenced from:
ngraph::Node::generate_adjoints(ngraph::autodiff::Adjoints&, std::__1::vector<std::__1::shared_ptr<ngraph::Node>, std::__1::allocator<std::__1::shared_ptr<ngraph::Node> > > const&) in libinference_engine_s.a(ie_rtti.cpp.o)
"ngraph::Node::match_node(ngraph::pattern::Matcher*, ngraph::Output<ngraph::Node> const&)", referenced from:
vtable for ExecGraphInfoSerialization::ExecutionNode in libinference_engine_s.a(ie_rtti.cpp.o)
"ngraph::Node::match_value(ngraph::pattern::Matcher*, ngraph::Output<ngraph::Node> const&, ngraph::Output<ngraph::Node> const&)", referenced from:
vtable for ExecGraphInfoSerialization::ExecutionNode in libinference_engine_s.a(ie_rtti.cpp.o)
"ngraph::Node::constant_fold(std::__1::vector<ngraph::Output<ngraph::Node>, std::__1::allocator<ngraph::Output<ngraph::Node> > >&, std::__1::vector<ngraph::Output<ngraph::Node>, std::__1::allocator<ngraph::Output<ngraph::Node> > > const&)", referenced from:
vtable for ExecGraphInfoSerialization::ExecutionNode in libinference_engine_s.a(ie_rtti.cpp.o)
"ngraph::Node::set_arguments(std::__1::vector<ngraph::Output<ngraph::Node>, std::__1::allocator<ngraph::Output<ngraph::Node> > > const&)", referenced from:
ExecGraphInfoSerialization::ExecutionNode::clone_with_new_inputs(std::__1::vector<ngraph::Output<ngraph::Node>, std::__1::allocator<ngraph::Output<ngraph::Node> > > const&) const in libinference_engine_s.a(ie_rtti.cpp.o)
"ngraph::Node::set_output_type(unsigned long, ngraph::element::Type const&, ngraph::PartialShape const&)", referenced from:
ExecGraphInfoSerialization::ExecutionNode::clone_with_new_inputs(std::__1::vector<ngraph::Output<ngraph::Node>, std::__1::allocator<ngraph::Output<ngraph::Node> > > const&) const in libinference_engine_s.a(ie_rtti.cpp.o)
"ngraph::Node::m_next_instance_id", referenced from:
std::__1::shared_ptr<ExecGraphInfoSerialization::ExecutionNode> std::__1::shared_ptr<ExecGraphInfoSerialization::ExecutionNode>::make_shared<>() in libinference_engine_s.a(ie_rtti.cpp.o)
"ngraph::Node::validate_and_infer_types()", referenced from:
vtable for ExecGraphInfoSerialization::ExecutionNode in libinference_engine_s.a(ie_rtti.cpp.o)
"ngraph::Node::evaluate(std::__1::vector<std::__1::shared_ptr<ngraph::runtime::HostTensor>, std::__1::allocator<std::__1::shared_ptr<ngraph::runtime::HostTensor> > > const&, std::__1::vector<std::__1::shared_ptr<ngraph::runtime::HostTensor>, std::__1::allocator<std::__1::shared_ptr<ngraph::runtime::HostTensor> > > const&)", referenced from:
vtable for ExecGraphInfoSerialization::ExecutionNode in libinference_engine_s.a(ie_rtti.cpp.o)
"ngraph::Node::~Node()", referenced from:
ExecGraphInfoSerialization::ExecutionNode::~ExecutionNode() in libinference_engine_s.a(ie_rtti.cpp.o)
ExecGraphInfoSerialization::ExecutionNode::~ExecutionNode() in libinference_engine_s.a(ie_rtti.cpp.o)
std::__1::__shared_ptr_emplace<ExecGraphInfoSerialization::ExecutionNode, std::__1::allocator<ExecGraphInfoSerialization::ExecutionNode> >::~__shared_ptr_emplace() in libinference_engine_s.a(ie_rtti.cpp.o)
std::__1::__shared_ptr_emplace<ExecGraphInfoSerialization::ExecutionNode, std::__1::allocator<ExecGraphInfoSerialization::ExecutionNode> >::~__shared_ptr_emplace() in libinference_engine_s.a(ie_rtti.cpp.o)
"ngraph::Node::is_dynamic() const", referenced from:
vtable for ExecGraphInfoSerialization::ExecutionNode in libinference_engine_s.a(ie_rtti.cpp.o)
"ngraph::Node::description() const", referenced from:
vtable for ExecGraphInfoSerialization::ExecutionNode in libinference_engine_s.a(ie_rtti.cpp.o)
"ngraph::Node::is_constant() const", referenced from:
vtable for ExecGraphInfoSerialization::ExecutionNode in libinference_engine_s.a(ie_rtti.cpp.o)
"ngraph::Node::get_arguments() const", referenced from:
vtable for ExecGraphInfoSerialization::ExecutionNode in libinference_engine_s.a(ie_rtti.cpp.o)
"ngraph::Node::get_output_size() const", referenced from:
ExecGraphInfoSerialization::ExecutionNode::clone_with_new_inputs(std::__1::vector<ngraph::Output<ngraph::Node>, std::__1::allocator<ngraph::Output<ngraph::Node> > > const&) const in libinference_engine_s.a(ie_rtti.cpp.o)
"ngraph::Node::write_description(std::__1::basic_ostream<char, std::__1::char_traits<char> >&, unsigned int) const", referenced from:
vtable for ExecGraphInfoSerialization::ExecutionNode in libinference_engine_s.a(ie_rtti.cpp.o)
"ngraph::Node::copy_with_new_args(std::__1::vector<std::__1::shared_ptr<ngraph::Node>, std::__1::allocator<std::__1::shared_ptr<ngraph::Node> > > const&) const", referenced from:
vtable for ExecGraphInfoSerialization::ExecutionNode in libinference_engine_s.a(ie_rtti.cpp.o)
"ngraph::Node::get_output_element_type(unsigned long) const", referenced from:
ExecGraphInfoSerialization::ExecutionNode::clone_with_new_inputs(std::__1::vector<ngraph::Output<ngraph::Node>, std::__1::allocator<ngraph::Output<ngraph::Node> > > const&) const in libinference_engine_s.a(ie_rtti.cpp.o)
"ngraph::Node::get_default_output_index() const", referenced from:
vtable for ExecGraphInfoSerialization::ExecutionNode in libinference_engine_s.a(ie_rtti.cpp.o)
"ngraph::Node::get_output_partial_shape(unsigned long) const", referenced from:
ExecGraphInfoSerialization::ExecutionNode::clone_with_new_inputs(std::__1::vector<ngraph::Output<ngraph::Node>, std::__1::allocator<ngraph::Output<ngraph::Node> > > const&) const in libinference_engine_s.a(ie_rtti.cpp.o)
"ngraph::Node::get_autob() const", referenced from:
vtable for ExecGraphInfoSerialization::ExecutionNode in libinference_engine_s.a(ie_rtti.cpp.o)
"ngraph::Node::is_output() const", referenced from:
vtable for ExecGraphInfoSerialization::ExecutionNode in libinference_engine_s.a(ie_rtti.cpp.o)
"typeinfo for ngraph::Node", referenced from:
typeinfo for ExecGraphInfoSerialization::ExecutionNode in libinference_engine_s.a(ie_rtti.cpp.o)
"vtable for ngraph::Node", referenced from:
std::__1::shared_ptr<ExecGraphInfoSerialization::ExecutionNode> std::__1::shared_ptr<ExecGraphInfoSerialization::ExecutionNode>::make_shared<>() in libinference_engine_s.a(ie_rtti.cpp.o)
NOTE: a missing vtable usually means the first non-inline virtual member function has no definition.
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Did anyone had the same problem as me, and did anyone know how to fix it?
First and foremost just need to cross check with you on your toolkit installation. Since you are trying to run a model already, I assume you already set it up properly as in (fyi latest version is 2020.4): https://docs.openvinotoolkit.org/latest/openvino_docs_install_guides_installing_openvino_macos.html
The error that you are getting, the Undefined symbols for architecture x86_64 is an Xcode build failure indicating you missed out something in your inference engine or the way you link the model with certain resources are incorrect or some other reasons. As long as this error persist you won't be able to compile your code. That is why you got the linker command failed with exit code 1.
Most error occurs because the users did not Set the OpenVINO environment variables or Configure the Model Optimizer correctly. This is why it's really important to Run verification scripts to verify installation and compile samples.
Before running any custom model, it is good to have a solid working Openvino environment, hence please help to check whether you could run the default models as in example here https://docs.openvinotoolkit.org/latest/openvino_docs_install_guides_installing_openvino_macos.html
By default, you should already have pre-trained models including open zoo model, Model Optimizer and Inference Engine which are working example to work with if you configured the toolkit correctly. These should already located in your installed toolkit's directory which you don't have to install separately from other resources.
Please take a note that you need:
CMake 3.4 or higher,
Python 3.5 or higher,
Apple Xcode Command Line Tools*,
(Optional) Apple Xcode* IDE (not required for OpenVINO, but useful for development),
And supported MAC OS is macOS 10.14.4*
Again, please help to cross check what you have in your Openvino environment and steps you had used to configure with the official documentation https://docs.openvinotoolkit.org/latest/openvino_docs_install_guides_installing_openvino_macos.html
Thanks!

CMake works when I link a dynamic library but not a static library

When I link a dynamic library with CMake, create the make file and then use make, it compiles and builds correctly.
When I link a static library, CMake doesn't complain but when I run make, it throws a linker error at me, even though all I did was replace the .dylib with a .a of the same name.
This is my CMake file linking to a static library:
cmake_minimum_required (VERSION 3.0)
add_executable (TEST main.cpp)
include_directories ("${CMAKE_SOURCE_DIR}/Dependencies/libpqxx/include")
target_link_libraries (TEST "${CMAKE_SOURCE_DIR}/Dependencies/libpqxx/lib/libpqxx.a")
Any ideas?
Output for cmake:
>> cmake .
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/john/Documents/Test/src
Output for make:
>> make
[ 33%] Linking CXX executable TEST
Undefined symbols for architecture x86_64:
"_PQbackendPID", referenced from:
pqxx::connection_base::backendpid() const in libpqxx.a(connection_base.o)
"_PQcancel", referenced from:
pqxx::connection_base::cancel_query() in libpqxx.a(connection_base.o)
"_PQclear", referenced from:
pqxx::internal::clear_result(pg_result const*) in libpqxx.a(result.o)
"_PQclientEncoding", referenced from:
pqxx::connection_base::encoding_code() in libpqxx.a(connection_base.o)
"_PQcmdStatus", referenced from:
pqxx::result::cmd_status() const in libpqxx.a(result.o)
"_PQcmdTuples", referenced from:
pqxx::result::affected_rows() const in libpqxx.a(result.o)
"_PQconnectPoll", referenced from:
pqxx::connect_async::do_completeconnect(pg_conn*) in libpqxx.a(connection.o)
"_PQconnectStart", referenced from:
pqxx::connect_async::do_startconnect(pg_conn*) in libpqxx.a(connection.o)
"_PQconnectdb", referenced from:
pqxx::connectionpolicy::normalconnect(pg_conn*) in libpqxx.a(connection.o)
"_PQconsumeInput", referenced from:
pqxx::connection_base::consume_input() in libpqxx.a(connection_base.o)
"_PQdb", referenced from:
pqxx::connection_base::dbname() in libpqxx.a(connection_base.o)
"_PQencryptPassword", referenced from:
pqxx::encrypt_password(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) in libpqxx.a(connection_base.o)
"_PQendcopy", referenced from:
pqxx::connection_base::write_copy_line(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) in libpqxx.a(connection_base.o)
"_PQerrorMessage", referenced from:
pqxx::connection_base::err_msg() const in libpqxx.a(connection_base.o)
pqxx::connectionpolicy::normalconnect(pg_conn*) in libpqxx.a(connection.o)
pqxx::connect_direct::do_startconnect(pg_conn*) in libpqxx.a(connection.o)
pqxx::connect_async::do_startconnect(pg_conn*) in libpqxx.a(connection.o)
pqxx::connect_async::do_completeconnect(pg_conn*) in libpqxx.a(connection.o)
"_PQescapeByteaConn", referenced from:
pqxx::connection_base::esc_raw(unsigned char const*, unsigned long) in libpqxx.a(connection_base.o)
"_PQescapeIdentifier", referenced from:
pqxx::connection_base::quote_name(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) in libpqxx.a(connection_base.o)
"_PQescapeStringConn", referenced from:
pqxx::connection_base::esc(char const*, unsigned long) in libpqxx.a(connection_base.o)
"_PQexec", referenced from:
pqxx::connection_base::exec(char const*, int) in libpqxx.a(connection_base.o)
pqxx::connection_base::add_receiver(pqxx::notification_receiver*) in libpqxx.a(connection_base.o)
"_PQexecParams", referenced from:
pqxx::connection_base::parameterized_exec(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, char const* const*, int const*, int const*, int) in libpqxx.a(connection_base.o)
pqxx::connection_base::exec_params(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, pqxx::internal::params const&) in libpqxx.a(connection_base.o)
"_PQexecPrepared", referenced from:
pqxx::connection_base::prepared_exec(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, char const* const*, int const*, int const*, int) in libpqxx.a(connection_base.o)
pqxx::connection_base::exec_prepared(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, pqxx::internal::params const&) in libpqxx.a(connection_base.o)
"_PQfinish", referenced from:
pqxx::connectionpolicy::normalconnect(pg_conn*) in libpqxx.a(connection.o)
pqxx::connectionpolicy::do_disconnect(pg_conn*) in libpqxx.a(connection.o)
"_PQfname", referenced from:
pqxx::result::column_name(unsigned int) const in libpqxx.a(result.o)
"_PQfnumber", referenced from:
pqxx::result::column_number(char const*) const in libpqxx.a(row.o)
"_PQfreeCancel", referenced from:
(anonymous namespace)::cancel_wrapper::~cancel_wrapper() in libpqxx.a(connection_base.o)
"_PQfreemem", referenced from:
pqxx::internal::freepqmem(void const*) in libpqxx.a(util.o)
"_PQftable", referenced from:
pqxx::result::column_table(unsigned int) const in libpqxx.a(result.o)
"_PQftablecol", referenced from:
pqxx::result::table_column(unsigned int) const in libpqxx.a(result.o)
"_PQftype", referenced from:
pqxx::result::column_type(unsigned int) const in libpqxx.a(result.o)
"_PQgetCancel", referenced from:
pqxx::connection_base::cancel_query() in libpqxx.a(connection_base.o)
"_PQgetCopyData", referenced from:
pqxx::connection_base::read_copy_line(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >&) in libpqxx.a(connection_base.o)
"_PQgetResult", referenced from:
pqxx::connection_base::set_up_state() in libpqxx.a(connection_base.o)
pqxx::connection_base::read_copy_line(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >&) in libpqxx.a(connection_base.o)
pqxx::connection_base::end_copy_write() in libpqxx.a(connection_base.o)
pqxx::connection_base::get_result() in libpqxx.a(connection_base.o)
"_PQgetisnull", referenced from:
pqxx::result::get_is_null(unsigned long, unsigned int) const in libpqxx.a(result.o)
"_PQgetlength", referenced from:
pqxx::result::get_length(unsigned long, unsigned int) const in libpqxx.a(result.o)
"_PQgetvalue", referenced from:
pqxx::result::GetValue(unsigned long, unsigned int) const in libpqxx.a(result.o)
"_PQhost", referenced from:
pqxx::connection_base::hostname() in libpqxx.a(connection_base.o)
"_PQisBusy", referenced from:
pqxx::connection_base::is_busy() const in libpqxx.a(connection_base.o)
"_PQisthreadsafe", referenced from:
pqxx::describe_thread_safety() in libpqxx.a(util.o)
"_PQnfields", referenced from:
pqxx::result::columns() const in libpqxx.a(result.o)
"_PQnotifies", referenced from:
pqxx::connection_base::get_notifs() in libpqxx.a(connection_base.o)
"_PQntuples", referenced from:
pqxx::result::size() const in libpqxx.a(result.o)
pqxx::result::empty() const in libpqxx.a(result.o)
"_PQoidValue", referenced from:
pqxx::result::inserted_oid() const in libpqxx.a(result.o)
"_PQport", referenced from:
pqxx::connection_base::port() in libpqxx.a(connection_base.o)
"_PQprepare", referenced from:
pqxx::connection_base::register_prepared(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) in libpqxx.a(connection_base.o)
"_PQprotocolVersion", referenced from:
pqxx::connection_base::protocol_version() const in libpqxx.a(connection_base.o)
"_PQputCopyData", referenced from:
pqxx::connection_base::write_copy_line(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) in libpqxx.a(connection_base.o)
"_PQputCopyEnd", referenced from:
pqxx::connection_base::end_copy_write() in libpqxx.a(connection_base.o)
"_PQreset", referenced from:
pqxx::connection_base::reset() in libpqxx.a(connection_base.o)
"_PQresultErrorField", referenced from:
pqxx::result::ThrowSQLError(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) const in libpqxx.a(result.o)
pqxx::result::errorposition() const in libpqxx.a(result.o)
"_PQresultErrorMessage", referenced from:
pqxx::result::StatusError() const in libpqxx.a(result.o)
"_PQresultStatus", referenced from:
pqxx::result::StatusError() const in libpqxx.a(result.o)
"_PQsendQuery", referenced from:
pqxx::connection_base::set_up_state() in libpqxx.a(connection_base.o)
pqxx::connection_base::start_exec(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) in libpqxx.a(connection_base.o)
"_PQserverVersion", referenced from:
pqxx::connection_base::read_capabilities() in libpqxx.a(connection_base.o)
"_PQsetErrorVerbosity", referenced from:
pqxx::connection_base::set_verbosity(pqxx::connection_base::error_verbosity) in libpqxx.a(connection_base.o)
"_PQsetNoticeProcessor", referenced from:
pqxx::connection_base::set_up_state() in libpqxx.a(connection_base.o)
pqxx::connection_base::close() in libpqxx.a(connection_base.o)
"_PQsocket", referenced from:
(anonymous namespace)::socket_of(pg_conn const*) in libpqxx.a(connection_base.o)
"_PQstatus", referenced from:
pqxx::connection_base::status() const in libpqxx.a(connection_base.o)
pqxx::connectionpolicy::normalconnect(pg_conn*) in libpqxx.a(connection.o)
pqxx::connect_direct::do_startconnect(pg_conn*) in libpqxx.a(connection.o)
pqxx::connect_async::do_startconnect(pg_conn*) in libpqxx.a(connection.o)
"_PQtrace", referenced from:
pqxx::connection_base::internal_set_trace() in libpqxx.a(connection_base.o)
"_PQunescapeBytea", referenced from:
pqxx::connection_base::unesc_raw(char const*) in libpqxx.a(connection_base.o)
"_PQuntrace", referenced from:
pqxx::connection_base::internal_set_trace() in libpqxx.a(connection_base.o)
"_PQuser", referenced from:
pqxx::connection_base::username() in libpqxx.a(connection_base.o)
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [TEST] Error 1
make[1]: *** [CMakeFiles/TEST.dir/all] Error 2
make: *** [all] Error 2
if you send error messages it'd be better , but try this:
link_directories(${CMAKE_SOURCE_DIR}/Dependencies/libpqxx/lib)
target_link_libraries (TEST pqxx)
I've figured it out. I was just missing some dependencies for the pqxx library. I've added a reference to libpq.a, libssl.a, and libcrypto.a as well as their include/ directories and it ended up working. I guess .dylib files link to dependencies by themselves but you have to manually include them with static libraries?

How to get face_detection_ex.cpp in dlib to work in c++?

I'm new to c++, so sorry if there is an obvious solution I'm missing. I'm trying to run this example code for dlib in c++. I'm getting this error...
In file included from /Users/john/ClionProjects/dlib/examples/face_detection_ex.cpp:41:
In file included from /Users/john/ClionProjects/dlib/dlib/../dlib/gui_widgets.h:13:
In file included from /Users/john/ClionProjects/dlib/dlib/../dlib/image_processing/../gui_widgets/widgets.h:9:
In file included from /Users/john/ClionProjects/dlib/dlib/../dlib/image_processing/../gui_widgets/drawable.h:8:
In file included from /Users/john/ClionProjects/dlib/dlib/../dlib/image_processing/../gui_widgets/../gui_core.h:14:
In file included from /Users/john/ClionProjects/dlib/dlib/../dlib/image_processing/../gui_core/xlib.h:4:
/Users/john/ClionProjects/dlib/dlib/../dlib/image_processing/../gui_core/gui_core_kernel_2.h:11:2: error: "DLIB_NO_GUI_SUPPORT is defined so you can't use the GUI code. Turn DLIB_NO_GUI_SUPPORT off if you want to use it."
#error "DLIB_NO_GUI_SUPPORT is defined so you can't use the GUI code. Turn DLIB_NO_GUI_SUPPORT off if you want to use it."
^
/Users/johnoberhauser/ClionProjects/dlib/dlib/../dlib/image_processing/../gui_core/gui_core_kernel_2.h:12:2: error: "Also make sure you have libx11-dev installed on your system"
#error "Also make sure you have libx11-dev installed on your system"
I've tried going into /dlib/CMakeLists.txt and adding
set(DLIB_NO_GUI_SUPPORT OFF)
I know it's found the X11 package as I'm not getting a message from the cmake there (and I just installed XQuartz)
Also, I'm using Clion, so I'm not running cmake from the command line. And I'm on OSX
Edit: I tried removing the parts of the code that use the gui, just to see if it would work. But I then get this error:
Undefined symbols for architecture x86_64:
"_USER_ERROR__missing_dlib_all_source_cpp_file__OR__inconsistent_use_of_DEBUG_or_ENABLE_ASSERTS_preprocessor_directives", referenced from:
_dlib_check_consistent_assert_usage in main.cpp.o
"_cblas_saxpy", referenced from:
dlib::blas_bindings::cblas_axpy(int, float, float const*, int, float*, int) in main.cpp.o
"_cblas_sscal", referenced from:
dlib::blas_bindings::cblas_scal(int, float, float*) in main.cpp.o
"_dgesvd_", referenced from:
dlib::lapack::binding::gesvd(char, char, int, int, double*, int, double*, double*, int, double*, int, double*, int) in main.cpp.o
"_png_create_info_struct", referenced from:
dlib::png_loader::read_image(char const*) in libdlib.a(png_loader.cpp.o)
"_png_create_read_struct", referenced from:
dlib::png_loader::read_image(char const*) in libdlib.a(png_loader.cpp.o)
"_png_destroy_read_struct", referenced from:
dlib::png_loader::read_image(char const*) in libdlib.a(png_loader.cpp.o)
dlib::png_loader::~png_loader() in libdlib.a(png_loader.cpp.o)
dlib::png_loader::~png_loader() in libdlib.a(png_loader.cpp.o)
"_png_get_bit_depth", referenced from:
dlib::png_loader::read_image(char const*) in libdlib.a(png_loader.cpp.o)
"_png_get_color_type", referenced from:
dlib::png_loader::read_image(char const*) in libdlib.a(png_loader.cpp.o)
"_png_get_image_height", referenced from:
dlib::png_loader::read_image(char const*) in libdlib.a(png_loader.cpp.o)
"_png_get_image_width", referenced from:
dlib::png_loader::read_image(char const*) in libdlib.a(png_loader.cpp.o)
"_png_get_rows", referenced from:
dlib::png_loader::read_image(char const*) in libdlib.a(png_loader.cpp.o)
"_png_init_io", referenced from:
dlib::png_loader::read_image(char const*) in libdlib.a(png_loader.cpp.o)
"_png_read_png", referenced from:
dlib::png_loader::read_image(char const*) in libdlib.a(png_loader.cpp.o)
"_png_set_longjmp_fn", referenced from:
dlib::png_loader::read_image(char const*) in libdlib.a(png_loader.cpp.o)
dlib::png_loader_user_error_fn_silent(png_struct_def*, char const*) in libdlib.a(png_loader.cpp.o)
"_png_set_palette_to_rgb", referenced from:
dlib::png_loader::read_image(char const*) in libdlib.a(png_loader.cpp.o)
"_png_set_sig_bytes", referenced from:
dlib::png_loader::read_image(char const*) in libdlib.a(png_loader.cpp.o)
"_png_sig_cmp", referenced from:
dlib::png_loader::read_image(char const*) in libdlib.a(png_loader.cpp.o)
ld: symbol(s) not found for architecture x86_64
I think this is a separate issue from the first one, but idk, maybe they are related? For this issue, I've tried doing what was mentioned here https://github.com/davisking/dlib/issues/57 I made the link for the first part, then added these lines to my cmakelist.txt
include_directories(../../../../usr/X11/lib)
include_directories(../../../../usr/local/include)
include_directories(../../../../usr/local/lib)
Didn't seem to fix the issue though.
Edit 2: So I think both these issues are resolved now. I think added those include_directories lines that I mentioned above help. Also, I started using cmake from the command line, instead of with clion.
However, I am now getting a new error :/
Undefined symbols for architecture x86_64:
"dlib::base_window::invalidate_rectangle(dlib::rectangle const&)", referenced from:
void dlib::image_display::set_image<dlib::array2d<unsigned char, dlib::memory_manager_stateless_kernel_1<char> > >(dlib::array2d<unsigned char, dlib::memory_manager_stateless_kernel_1<char> > const&) in main.cpp.o
"dlib::base_window::set_size(int, int)", referenced from:
void dlib::image_window::set_image<dlib::array2d<unsigned char, dlib::memory_manager_stateless_kernel_1<char> > >(dlib::array2d<unsigned char, dlib::memory_manager_stateless_kernel_1<char> > const&) in main.cpp.o
"dlib::image_window::add_overlay(std::__1::vector<dlib::image_display::overlay_rect, std::__1::allocator<dlib::image_display::overlay_rect> > const&)", referenced from:
void dlib::image_window::add_overlay<dlib::rgb_pixel>(std::__1::vector<dlib::rectangle, std::__1::allocator<dlib::rectangle> > const&, dlib::rgb_pixel) in main.cpp.o
"dlib::image_window::clear_overlay()", referenced from:
_main in main.cpp.o
"dlib::image_window::image_window()", referenced from:
_main in main.cpp.o
"dlib::image_window::~image_window()", referenced from:
_main in main.cpp.o
"dlib::popup_menu_region::disable()", referenced from:
void dlib::image_display::set_image<dlib::array2d<unsigned char, dlib::memory_manager_stateless_kernel_1<char> > >(dlib::array2d<unsigned char, dlib::memory_manager_stateless_kernel_1<char> > const&) in main.cpp.o
"dlib::scrollable_region::set_total_rect_size(unsigned long, unsigned long)", referenced from:
void dlib::image_display::set_image<dlib::array2d<unsigned char, dlib::memory_manager_stateless_kernel_1<char> > >(dlib::array2d<unsigned char, dlib::memory_manager_stateless_kernel_1<char> > const&) in main.cpp.o
"dlib::draw_sunken_rectangle(dlib::canvas const&, dlib::rectangle const&, unsigned char)", referenced from:
dlib::scrollable_region_style_default::draw_scrollable_region_border(dlib::canvas const&, dlib::rectangle const&, bool) const in main.cpp.o
"dlib::image_display::get_image_display_rect() const", referenced from:
void dlib::image_window::set_image<dlib::array2d<unsigned char, dlib::memory_manager_stateless_kernel_1<char> > >(dlib::array2d<unsigned char, dlib::memory_manager_stateless_kernel_1<char> > const&) in main.cpp.o
ld: symbol(s) not found for architecture x86_64
One issue after another :/
Edit 3: Success! So I was using Clion for compiling. Even though the cmake from clion is the same version as the cmake I'm using in the command line, it just didn't work for some reason.
I solved this by deleting the "cmake-build-debug" directory.
Then reopen the project(CLion will regenerate it).
It seems there remain some cache files would affect the compiling.
But before this step, please make sure you do install XQuartz.

xcode 7.2.1+ os 10.11.9 + opencv3.1.0 Undefined symbols for architecture x86_64?

I have a cpp file which works fine with g++ before upgrading these stuff.
Currently, when running : g++ -I/usr/local/Cellar/opencv3/3.1.0_1/include -stdlib=libc++ bs.cpp -o bs
Results are following:
Undefined symbols for architecture x86_64:
"cv::namedWindow(cv::String const&, int)", referenced from:
_main in bs-df9f1a.o
"cv::VideoCapture::read(cv::_OutputArray const&)", referenced from:
processVideo(char*) in bs-df9f1a.o
"cv::VideoCapture::release()", referenced from:
processVideo(char*) in bs-df9f1a.o
"cv::VideoCapture::VideoCapture(cv::String const&)", referenced from:
processVideo(char*) in bs-df9f1a.o
"cv::VideoCapture::~VideoCapture()", referenced from:
processVideo(char*) in bs-df9f1a.o
"cv::destroyAllWindows()", referenced from:
_main in bs-df9f1a.o
"cv::createBackgroundSubtractorMOG2(int, double, bool)", referenced from:
_main in bs-df9f1a.o
"cv::Mat::deallocate()", referenced from:
cv::Mat::release() in bs-df9f1a.o
"cv::Mat::copySize(cv::Mat const&)", referenced from:
cv::Mat::operator=(cv::Mat const&) in bs-df9f1a.o
"cv::String::deallocate()", referenced from:
cv::String::~String() in bs-df9f1a.o
"cv::String::allocate(unsigned long)", referenced from:
cv::String::String(char const*) in bs-df9f1a.o
cv::String::String(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) in bs-df9f1a.o
"cv::imread(cv::String const&, int)", referenced from:
processImages(char*) in bs-df9f1a.o
"cv::imshow(cv::String const&, cv::_InputArray const&)", referenced from:
processVideo(char*) in bs-df9f1a.o
processImages(char*) in bs-df9f1a.o
"cv::putText(cv::_InputOutputArray const&, cv::String const&, cv::Point_<int>, int, double, cv::Scalar_<double>, int, int, bool)", referenced from:
processVideo(char*) in bs-df9f1a.o
processImages(char*) in bs-df9f1a.o
"cv::waitKey(int)", referenced from:
processVideo(char*) in bs-df9f1a.o
processImages(char*) in bs-df9f1a.o
"cv::fastFree(void*)", referenced from:
cv::Mat::~Mat() in bs-df9f1a.o
"cv::rectangle(cv::_InputOutputArray const&, cv::Point_<int>, cv::Point_<int>, cv::Scalar_<double> const&, int, int, int)", referenced from:
processVideo(char*) in bs-df9f1a.o
processImages(char*) in bs-df9f1a.o
"cv::VideoCapture::get(int) const", referenced from:
processVideo(char*) in bs-df9f1a.o
"cv::VideoCapture::isOpened() const", referenced from:
processVideo(char*) in bs-df9f1a.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
I do not know how to solve this problem, it's not related to source code or include, it's related to the linker. I see the post:C++ linking error after upgrading to Mac OS X 10.9 / Xcode 5.0.1
Which really sounds reasonable, but I do not know how to add -stdlib=libstdc++ to the linking command. ?
Hope sb could help. Thanks in advance.

Compilation errors while trying to link LLVM library

I am trying to use some LLVM API in my C++ code, and I end up getting linker errors. I am working on Apple MacOSX Lion. Using g++ for the compile. It is the CreateGlobalStringPtr which is throwing the error. This is LLVM 3.0.
Here's the code:
#define __STDC_LIMIT_MACROS
#define __STDC_CONSTANT_MACROS
#include "llvm/Support/DataTypes.h"
#include "llvm/Support/IRBuilder.h"
#include "llvm/LLVMContext.h"
#include "llvm/Module.h"
#include "llvm/Constants.h"
#include "llvm/Function.h"
#include "llvm/BasicBlock.h"
int main()
{
llvm::LLVMContext & context = llvm::getGlobalContext();
llvm::Module *module = new llvm::Module("top", context);
llvm::IRBuilder<> builder(context);
llvm::Value *helloWorld = builder.CreateGlobalStringPtr("hello world!\n");
}
g++ e.cpp /Developer/Platforms/iPhoneOS.platform/Developer/usr/llvm-gcc-4.2/libexec/gcc/i686-apple-darwin10/4.2.1/libllvmgcc.dylib
Undefined symbols for architecture x86_64:
"llvm::ConstantExpr::getGetElementPtr(llvm::Constant*, llvm::ArrayRef<llvm::Value*>, bool)", referenced from:
llvm::ConstantExpr::getInBoundsGetElementPtr(llvm::Constant*, llvm::ArrayRef<llvm::Value*>)in ccQDtIAW.o
"llvm::GetElementPtrInst::getIndexedType(llvm::Type*, llvm::ArrayRef<llvm::Value*>)", referenced from:
llvm::GetElementPtrInst::GetElementPtrInst(llvm::Value*, llvm::ArrayRef<llvm::Value*>, unsigned int, llvm::Twine const&, llvm::Instruction*)in ccQDtIAW.o
"llvm::PointerType::get(llvm::Type*, unsigned int)", referenced from:
llvm::GetElementPtrInst::GetElementPtrInst(llvm::Value*, llvm::ArrayRef<llvm::Value*>, unsigned int, llvm::Twine const&, llvm::Instruction*)in ccQDtIAW.o
"llvm::Instruction::Instruction(llvm::Type*, unsigned int, llvm::Use*, unsigned int, llvm::Instruction*)", referenced from:
llvm::GetElementPtrInst::GetElementPtrInst(llvm::Value*, llvm::ArrayRef<llvm::Value*>, unsigned int, llvm::Twine const&, llvm::Instruction*)in ccQDtIAW.o
"llvm::GetElementPtrInst::init(llvm::Value*, llvm::ArrayRef<llvm::Value*>, llvm::Twine const&)", referenced from:
llvm::GetElementPtrInst::GetElementPtrInst(llvm::Value*, llvm::ArrayRef<llvm::Value*>, unsigned int, llvm::Twine const&, llvm::Instruction*)in ccQDtIAW.o
"llvm::IRBuilderBase::CreateGlobalString(llvm::StringRef, llvm::Twine const&)", referenced from:
llvm::IRBuilder<true, llvm::ConstantFolder, llvm::IRBuilderDefaultInserter<true> >::CreateGlobalStringPtr(llvm::StringRef, llvm::Twine const&)in ccQDtIAW.o
"llvm::ConstantInt::get(llvm::IntegerType*, unsigned long long, bool)", referenced from:
llvm::IRBuilder<true, llvm::ConstantFolder, llvm::IRBuilderDefaultInserter<true> >::CreateGlobalStringPtr(llvm::StringRef, llvm::Twine const&)in ccQDtIAW.o
ld: symbol(s) not found for architecture x86_64
Why you're linking to some random .dylib (which is definitely generated from LLVM 2.9 or around, since it was the last release with llvm-gcc)? Use llvm-config the derive the proper flags for compiler / linker.