I am writing a program which uses Boost libraries. I had no problems with linking and using program options but I can't seem to make boost log working correctly.
Could anyone tell me what am I missing?
jamroot.jam
using clang : : : <compileflags>-Isrc/main/headers <compileflags>-std=c++11 <compileflags>-stdlib=libc++ <linkflags>-std=c++11 <linkflags>-stdlib=libc++ ;
lib boost_program_options boost_log ;
exe foghorn : [ glob src/main/cpp/*.cpp ] boost_program_options boost_log ;
This is the error I am getting:
"boost::log::v2s_mt_posix::record_view::public_data::destroy(boost::log::v2s_mt_posix::record_view::public_data const*)", referenced from:
boost::log::v2s_mt_posix::record::reset() in main.o
"boost::log::v2s_mt_posix::attribute_set::insert(boost::log::v2s_mt_posix::attribute_name, boost::log::v2s_mt_posix::attribute const&)", referenced from:
boost::log::v2s_mt_posix::sources::basic_logger<char, boost::log::v2s_mt_posix::sources::severity_logger<ESeverityLevel>, boost::log::v2s_mt_posix::sources::single_thread_model>::add_attribute_unlocked(boost::log::v2s_mt_posix::attribute_name const&, boost::log::v2s_mt_posix::attribute const&) in main.o
boost::log::v2s_mt_posix::aux::attribute_set_reference_proxy::operator=(boost::log::v2s_mt_posix::attribute const&) const in main.o
"boost::log::v2s_mt_posix::attribute_set::attribute_set(boost::log::v2s_mt_posix::attribute_set const&)", referenced from:
boost::log::v2s_mt_posix::sources::basic_logger<char, boost::log::v2s_mt_posix::sources::severity_logger<ESeverityLevel>, boost::log::v2s_mt_posix::sources::single_thread_model>::basic_logger(boost::log::v2s_mt_posix::sources::basic_logger<char, boost::log::v2s_mt_posix::sources::severity_logger<ESeverityLevel>, boost::log::v2s_mt_posix::sources::single_thread_model> const&) in main.o
"boost::log::v2s_mt_posix::attribute_set::attribute_set()", referenced from:
boost::log::v2s_mt_posix::sources::basic_logger<char, boost::log::v2s_mt_posix::sources::severity_logger<ESeverityLevel>, boost::log::v2s_mt_posix::sources::single_thread_model>::basic_logger() in main.o
"boost::log::v2s_mt_posix::attribute_set::~attribute_set()", referenced from:
boost::log::v2s_mt_posix::sources::basic_logger<char, boost::log::v2s_mt_posix::sources::severity_logger<ESeverityLevel>, boost::log::v2s_mt_posix::sources::single_thread_model>::~basic_logger() in main.o
"boost::log::v2s_mt_posix::attribute_name::get_id_from_string(char const*)", referenced from:
boost::log::v2s_mt_posix::attribute_name::attribute_name(char const*) in main.o
"void boost::log::v2s_mt_posix::init_from_stream<char>(std::__1::basic_istream<char, std::__1::char_traits<char> >&)", referenced from:
__ZL13gvLoggingInitPKc in main.o
"boost::log::v2s_mt_posix::aux::this_thread::get_id()", referenced from:
boost::log::v2s_mt_posix::attributes::current_thread_id::impl::dispatch(boost::log::v2s_mt_posix::type_dispatcher&) in main.o
boost::log::v2s_mt_posix::attributes::current_thread_id::impl::detach_from_thread() in main.o
"boost::log::v2s_mt_posix::aux::this_process::get_id()", referenced from:
boost::log::v2s_mt_posix::attributes::current_process_id::current_process_id() in main.o
"boost::log::v2s_mt_posix::aux::stream_provider<char>::release_compound(boost::log::v2s_mt_posix::aux::stream_provider<char>::stream_compound*)", referenced from:
boost::log::v2s_mt_posix::aux::record_pump<boost::log::v2s_mt_posix::sources::severity_logger<ESeverityLevel> >::auto_release::~auto_release() in main.o
"boost::log::v2s_mt_posix::aux::stream_provider<char>::allocate_compound(boost::log::v2s_mt_posix::record&)", referenced from:
boost::log::v2s_mt_posix::aux::record_pump<boost::log::v2s_mt_posix::sources::severity_logger<ESeverityLevel> >::record_pump(boost::log::v2s_mt_posix::sources::severity_logger<ESeverityLevel>&, boost::log::v2s_mt_posix::record&) in main.o
"boost::log::v2s_mt_posix::aux::get_process_name()", referenced from:
boost::log::v2s_mt_posix::attributes::current_process_name::current_process_name() in main.o
"boost::log::v2s_mt_posix::aux::once_block_sentry::commit()", referenced from:
boost::log::v2s_mt_posix::aux::lazy_singleton<boost::log::v2s_mt_posix::sources::aux::logger_singleton<SLogger>, boost::shared_ptr<boost::log::v2s_mt_posix::sources::aux::logger_holder<boost::log::v2s_mt_posix::sources::severity_logger<ESeverityLevel> > > >::get() in main.o
"boost::log::v2s_mt_posix::aux::once_block_sentry::rollback()", referenced from:
boost::log::v2s_mt_posix::aux::once_block_sentry::~once_block_sentry() in main.o
"boost::log::v2s_mt_posix::aux::default_attribute_names::severity()", referenced from:
boost::log::v2s_mt_posix::sources::basic_severity_logger<boost::log::v2s_mt_posix::sources::basic_logger<char, boost::log::v2s_mt_posix::sources::severity_logger<ESeverityLevel>, boost::log::v2s_mt_posix::sources::single_thread_model>, ESeverityLevel>::basic_severity_logger() in main.o
boost::log::v2s_mt_posix::sources::basic_severity_logger<boost::log::v2s_mt_posix::sources::basic_logger<char, boost::log::v2s_mt_posix::sources::severity_logger<ESeverityLevel>, boost::log::v2s_mt_posix::sources::single_thread_model>, ESeverityLevel>::basic_severity_logger(boost::log::v2s_mt_posix::sources::basic_severity_logger<boost::log::v2s_mt_posix::sources::basic_logger<char, boost::log::v2s_mt_posix::sources::severity_logger<ESeverityLevel>, boost::log::v2s_mt_posix::sources::single_thread_model>, ESeverityLevel> const&) in main.o
"boost::log::v2s_mt_posix::aux::unhandled_exception_count()", referenced from:
boost::log::v2s_mt_posix::aux::record_pump<boost::log::v2s_mt_posix::sources::severity_logger<ESeverityLevel> >::~record_pump() in main.o
boost::log::v2s_mt_posix::aux::record_pump<boost::log::v2s_mt_posix::sources::severity_logger<ESeverityLevel> >::record_pump(boost::log::v2s_mt_posix::sources::severity_logger<ESeverityLevel>&, boost::log::v2s_mt_posix::record&) in main.o
"boost::log::v2s_mt_posix::aux::attach_attribute_name_info(boost::exception&, boost::log::v2s_mt_posix::attribute_name const&)", referenced from:
boost::log::v2s_mt_posix::value_extractor<ESeverityLevel, boost::log::v2s_mt_posix::fallback_to_none, tag::severity>::operator()(boost::log::v2s_mt_posix::attribute_name const&, boost::log::v2s_mt_posix::attribute_value_set const&) const in main.o
"boost::log::v2s_mt_posix::core::set_filter(boost::log::v2s_mt_posix::filter const&)", referenced from:
__ZL13gvLoggingInitPKc in main.o
"boost::log::v2s_mt_posix::core::open_record(boost::log::v2s_mt_posix::attribute_set const&)", referenced from:
boost::log::v2s_mt_posix::record boost::log::v2s_mt_posix::sources::basic_logger<char, boost::log::v2s_mt_posix::sources::severity_logger<ESeverityLevel>, boost::log::v2s_mt_posix::sources::single_thread_model>::open_record_unlocked<boost::parameter::aux::tagged_argument<boost::log::v2s_mt_posix::keywords::tag::severity, ESeverityLevel const> >(boost::parameter::aux::tagged_argument<boost::log::v2s_mt_posix::keywords::tag::severity, ESeverityLevel const> const&) in main.o
"boost::log::v2s_mt_posix::core::push_record_move(boost::log::v2s_mt_posix::record&)", referenced from:
boost::log::v2s_mt_posix::sources::basic_logger<char, boost::log::v2s_mt_posix::sources::severity_logger<ESeverityLevel>, boost::log::v2s_mt_posix::sources::single_thread_model>::push_record_unlocked(boost::log::v2s_mt_posix::record&&) in main.o
"boost::log::v2s_mt_posix::core::add_global_attribute(boost::log::v2s_mt_posix::attribute_name const&, boost::log::v2s_mt_posix::attribute const&)", referenced from:
__ZL13gvLoggingInitPKc in main.o
"boost::log::v2s_mt_posix::core::get()", referenced from:
__ZL13gvLoggingInitPKc in main.o
boost::log::v2s_mt_posix::sources::basic_logger<char, boost::log::v2s_mt_posix::sources::severity_logger<ESeverityLevel>, boost::log::v2s_mt_posix::sources::single_thread_model>::basic_logger() in main.o
boost::log::v2s_mt_posix::sources::basic_logger<char, boost::log::v2s_mt_posix::sources::severity_logger<ESeverityLevel>, boost::log::v2s_mt_posix::sources::single_thread_model>::basic_logger(boost::log::v2s_mt_posix::sources::basic_logger<char, boost::log::v2s_mt_posix::sources::severity_logger<ESeverityLevel>, boost::log::v2s_mt_posix::sources::single_thread_model> const&) in main.o
"boost::log::v2s_mt_posix::sources::aux::global_storage::get_or_init(std::type_info const&, boost::shared_ptr<boost::log::v2s_mt_posix::sources::aux::logger_holder_base> (*)())", referenced from:
boost::log::v2s_mt_posix::sources::aux::logger_singleton<SLogger>::init_instance() in main.o
"boost::log::v2s_mt_posix::sources::aux::get_severity_level()", referenced from:
boost::log::v2s_mt_posix::sources::aux::severity_level<ESeverityLevel>::set_value(ESeverityLevel) in main.o
boost::log::v2s_mt_posix::sources::aux::severity_level<ESeverityLevel>::impl::dispatch(boost::log::v2s_mt_posix::type_dispatcher&) in main.o
boost::log::v2s_mt_posix::sources::aux::severity_level<ESeverityLevel>::impl::detach_from_thread() in main.o
"boost::log::v2s_mt_posix::sources::aux::throw_odr_violation(std::type_info const&, std::type_info const&, boost::log::v2s_mt_posix::sources::aux::logger_holder_base const&)", referenced from:
boost::log::v2s_mt_posix::sources::aux::logger_singleton<SLogger>::init_instance() in main.o
"boost::log::v2s_mt_posix::attribute::impl::operator delete(void*, unsigned long)", referenced from:
boost::log::v2s_mt_posix::sources::aux::severity_level<ESeverityLevel>::severity_level() in main.o
boost::log::v2s_mt_posix::sources::aux::severity_level<ESeverityLevel>::impl::~impl() in main.o
boost::log::v2s_mt_posix::sources::aux::severity_level<ESeverityLevel>::impl::detach_from_thread() in main.o
boost::log::v2s_mt_posix::attributes::attribute_value_impl<ESeverityLevel>::~attribute_value_impl() in main.o
boost::log::v2s_mt_posix::attribute_value::impl::~impl() in main.o
boost::log::v2s_mt_posix::attribute::impl::~impl() in main.o
boost::log::v2s_mt_posix::attributes::current_thread_id::current_thread_id() in main.o
...
"boost::log::v2s_mt_posix::attribute::impl::operator new(unsigned long)", referenced from:
boost::log::v2s_mt_posix::sources::aux::severity_level<ESeverityLevel>::severity_level() in main.o
boost::log::v2s_mt_posix::sources::aux::severity_level<ESeverityLevel>::impl::detach_from_thread() in main.o
boost::log::v2s_mt_posix::attributes::current_thread_id::current_thread_id() in main.o
boost::log::v2s_mt_posix::attributes::current_thread_id::impl::detach_from_thread() in main.o
boost::log::v2s_mt_posix::attributes::constant<boost::log::v2s_mt_posix::aux::id<boost::log::v2s_mt_posix::aux::process> >::constant(boost::log::v2s_mt_posix::aux::id<boost::log::v2s_mt_posix::aux::process>&&) in main.o
boost::log::v2s_mt_posix::attributes::constant<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >::constant(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >&&) in main.o
boost::log::v2s_mt_posix::attributes::basic_clock<boost::log::v2s_mt_posix::attributes::local_time_traits>::basic_clock() in main.o
...
"boost::system::system_category()", referenced from:
___cxx_global_var_init2 in main.o
"boost::system::generic_category()", referenced from:
___cxx_global_var_init in main.o
___cxx_global_var_init1 in main.o
"boost::log::v2s_mt_posix::attribute_value_set::end() const", referenced from:
boost::log::v2s_mt_posix::value_extractor<ESeverityLevel, boost::log::v2s_mt_posix::fallback_to_none, tag::severity>::operator()(boost::log::v2s_mt_posix::attribute_name const&, boost::log::v2s_mt_posix::attribute_value_set const&) const in main.o
"boost::log::v2s_mt_posix::attribute_value_set::find(boost::log::v2s_mt_posix::attribute_name) const", referenced from:
boost::log::v2s_mt_posix::value_extractor<ESeverityLevel, boost::log::v2s_mt_posix::fallback_to_none, tag::severity>::operator()(boost::log::v2s_mt_posix::attribute_name const&, boost::log::v2s_mt_posix::attribute_value_set const&) const in main.o
"boost::log::v2s_mt_posix::aux::once_block_sentry::enter_once_block() const", referenced from:
boost::log::v2s_mt_posix::aux::once_block_sentry::executed() const in main.o
"boost::log::v2s_mt_posix::core::get_logging_enabled() const", referenced from:
__ZN5boost3log12v2s_mt_posix7sources22basic_composite_loggerIcNS2_15severity_loggerI14ESeverityLevelEENS2_19single_thread_modelENS2_8featuresIJNS2_8severityIS5_EEEEEE11open_recordINS_9parameter3aux15tagged_argumentINS1_8keywords3tag8severityEKS5_EEEENS1_6recordERKT_ in main.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
"clang++" -o "bin/clang-darwin-4.2.1/debug/foghorn" "bin/clang-darwin-4.2.1/debug/src/main/cpp/complement.o" "bin/clang-darwin-4.2.1/debug/src/main/cpp/degenerate.o" "bin/clang-darwin-4.2.1/debug/src/main/cpp/fastq.o" "bin/clang-darwin-4.2.1/debug/src/main/cpp/fastq_reader.o" "bin/clang-darwin-4.2.1/debug/src/main/cpp/interleave.o" "bin/clang-darwin-4.2.1/debug/src/main/cpp/interval_reader.o" "bin/clang-darwin-4.2.1/debug/src/main/cpp/interval_reader_test_tool.o" "bin/clang-darwin-4.2.1/debug/src/main/cpp/main.o" "bin/clang-darwin-4.2.1/debug/src/main/cpp/oligo_designer.o" "bin/clang-darwin-4.2.1/debug/src/main/cpp/reference_reader.o" "bin/clang-darwin-4.2.1/debug/src/main/cpp/reference_reader_test_tool.o" "bin/clang-darwin-4.2.1/debug/src/main/cpp/sequence_utils.o" "bin/clang-darwin-4.2.1/debug/src/main/cpp/tool.o" -lboost_log -lboost_program_options -g -std=c++11 -stdlib=libc++
...failed clang-darwin.link bin/clang-darwin-4.2.1/debug/foghorn...
...failed updating 1 target...
...updated 13 targets...
I had the same issue and in my case the problem was that I had boost compiled with dynamic libs only, and forgot to define BOOST_ALL_DYN_LINK.
http://www.boost.org/doc/libs/1_54_0/libs/log/doc/html/log/rationale/namespace_mangling.html
As a test, try to compile
http://www.boost.org/doc/libs/1_54_0/libs/log/example/doc/tutorial_fmt_stream.cpp
(#include <boost/log/support/date_time.hpp> should be added, the example is broken.)
and also add #define BOOST_LOG_DYN_LINK
I could compile the example with g++ tutorial_fmt_stream.cpp -Wall -L$BOOST/lib/ -I $BOOST/include/ -pthread -lboost_system -lboost_log_setup -lboost_log -lboost_date_time -lboost_thread -lrt -lboost_filesystem
If you are using cmake to manage your boost, just don't forget to have something like:
add_definitions(-DBOOST_LOG_DYN_LINK)
in your CMakeLists.txt
I had the same problem, which was a complicated linkage path. The message shows that is trying to link with the static libraries ( ....v2s ...), but the linker is only giving it dynamic libraries (because it is stupid).
Your build of Boost might be generating both .so and .a files, and gcc gets confused when both are present.
I had a library built with CMake that uses static Boost libraries. If you link this library to a program using a Makefile flow, the program needs to also specify the same static Boost libraries. However, the -l option for the linker is vague and not your friend here. If you built Boost to have both static (.a) and dynamic (.so) outputs, then the linker will chose the dynamic (.so) files first if you just use the -l option.
The workaround is to not use the -L and -l options to find the Boost static libraries (since it will fail), but to specify the full paths to the Boost libraries. For example,
gcc .... -L/opt/boost_1.55/lib -lboost_log
change to
gcc .... /opt/boost_1.55/lib/libboost_log.a
Another option is to specify the word -static to gcc, but this requires all libraries to be static, which probably won't work if you use anything besides boost (say the librt.so library).
If you are using
void boost::log::v2s_mt_posix::init_from_stream<char>(std::basic_istream<char, std::char_traits<char> >&)
function, then you need to link
libboost_log_setup.a
Related
I am getting this "symbol(s) not found in architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation)." Actually, these messages didn't appear until I upgraded to macOS Mojave.
The complete message I got is:
g++ -Wall -fexceptions -g -c /Users/suraj/Desktop/sfm/main.cpp -o obj/Debug/main.o
g++ -o bin/Debug/sfm obj/Debug/main.o
Undefined symbols for architecture x86_64:
"sf::CircleShape::CircleShape(float, unsigned long)", referenced from:
_main in main.o
"sf::RenderStates::Default", referenced from:
_main in main.o
"sf::RenderTarget::draw(sf::Drawable const&, sf::RenderStates const&)",
referenced from:
_main in main.o
"sf::RenderTarget::clear(sf::Color const&)", referenced from:
_main in main.o
"sf::RenderWindow::RenderWindow(sf::VideoMode, sf::String const&,
unsigned int, sf::ContextSettings const&)", referenced from:
_main in main.o
"sf::RenderWindow::~RenderWindow()", referenced from:
_main in main.o
"sf::Color::Green", referenced from:
_main in main.o
"sf::Color::Color(unsigned char, unsigned char, unsigned char, unsigned
char)", referenced from:
_main in main.o
"sf::Shape::setFillColor(sf::Color const&)", referenced from:
_main in main.o
"sf::Shape::~Shape()", referenced from:
sf::CircleShape::~CircleShape() in main.o
"sf::String::String(char const*, std::__1::locale const&)", referenced
from:
_main in main.o
"sf::Window::close()", referenced from:
_main in main.o
"sf::Window::display()", referenced from:
_main in main.o
"sf::Window::pollEvent(sf::Event&)", referenced from:
_main in main.o
"sf::VideoMode::VideoMode(unsigned int, unsigned int, unsigned int)",
referenced from:
_main in main.o
"sf::Window::isOpen() const", referenced from:
_main in main.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
The code is:
#include <SFML/Graphics.hpp>
int main()
{
sf::RenderWindow window(sf::VideoMode(400, 200), "SFML works!");
sf::CircleShape shape(100.f);
shape.setFillColor(sf::Color::Green);
while (window.isOpen())
{
sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
window.close();
}
window.clear();
window.draw(shape);
window.display();
}
return 0;
}
Please help.
Updated Answer - May 2019
It seems that the openal package is no longer in homebrew and that causes the instructions below to fail. I don't know the background behind it. Here is another approach.
You can find all the pkg-config related parts of sfml like this:
find /usr/local/Cellar/sfml -name \*pc
/usr/local/Cellar/sfml/2.5.1/lib/pkgconfig/sfml-network.pc
/usr/local/Cellar/sfml/2.5.1/lib/pkgconfig/sfml-all.pc
/usr/local/Cellar/sfml/2.5.1/lib/pkgconfig/sfml-graphics.pc
/usr/local/Cellar/sfml/2.5.1/lib/pkgconfig/sfml-audio.pc
/usr/local/Cellar/sfml/2.5.1/lib/pkgconfig/sfml-system.pc
/usr/local/Cellar/sfml/2.5.1/lib/pkgconfig/sfml-window.pc
It seems you cannot use sfml-all nor sfml-audio in the above list, so you will need to pick which parts you want to use and grab them individually, so if you want graphics, window and system:
pkg-config --libs --cflags sfml-graphics
-I/usr/local/Cellar/sfml/2.5.1/include
-I/usr/local/opt/freetype/include/freetype2
-I/usr/local/Cellar/sfml/2.5.1/include
-L/usr/local/Cellar/sfml/2.5.1/lib -lsfml-graphics -lsfml-window -lsfml-system
pkg-config --libs --cflags sfml-system
-I/usr/local/Cellar/sfml/2.5.1/include
-L/usr/local/Cellar/sfml/2.5.1/lib -lsfml-system
pkg-config --libs --cflags sfml-window
-I/usr/local/Cellar/sfml/2.5.1/include
-L/usr/local/Cellar/sfml/2.5.1/lib -lsfml-window -lsfml-system
So, you would compile with:
g++ main.cpp $(pkg-config --libs --cflags sfml-window sfml-system sfml-graphics) -o main
Original Answer
If you installed sfml via homebrew, I would suggest you also install pkg-config like this:
brew install pkg-config
Then you can get the switches needed to compile with:
pkg-config --libs --cflags sfml-all
Sample Output
-I/usr/local/Cellar/sfml/2.4.2_1/include -L/usr/local/Cellar/sfml/2.4.2_1/lib -lsfml-graphics -lsfml-window -lsfml-audio -lsfml-network -lsfml-system
So you can compile with:
g++ main.cpp $(pkg-config --libs --cflags sfml-all) -o main
I saw someone use swift code from android, using #_cdecl swift functions. I am able to compile to native using swiftc -emit-object, but when trying to link, I cant get the linker to work correctly..
I am trying to use g++ or clang(++) to compile and link a native swift object, has someone successfully done this already?
The errors I get are listed below:
Undefined symbols for architecture x86_64:
"__T0S2SBp21_builtinStringLiteral_Bw17utf8CodeUnitCountBi1_7isASCIItcfC", referenced from:
__T04main4testyyF in main.o
"__T0SSN", referenced from:
__T04main4testyyF in main.o
"__T0s27_allocateUninitializedArraySayxG_BptBwlFyp_Tgq5", referenced from:
__T04main4testyyF in main.o
"__T0s5printySayypGd_SS9separatorSS10terminatortF", referenced from:
__T04main4testyyF in main.o
"__T0s5printySayypGd_SS9separatorSS10terminatortFfA0_", referenced from:
__T04main4testyyF in main.o
"__T0s5printySayypGd_SS9separatorSS10terminatortFfA1_", referenced from:
__T04main4testyyF in main.o
"_swift_bridgeObjectRelease", referenced from:
__T04main4testyyF in main.o
"_swift_bridgeObjectRetain", referenced from:
__T04main4testyyF in main.o
So basically I have two questions, can it be done and how?
John.
So thanx to amine.ahd's pointer, I had the iphoneos toolchain location linked instead of the mac osx's.
The following command actually compiled and let me run a c program that calls a swift native library, even with parameters (char* on the c side, UnsafePointer on the swift side).
clang -o m m.o -lshared -L/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/macosx -L.
*-lshared is the libshared.so library that is compiled using the following command:
clang -shared -o libshared.so main.o -L/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/macosx
Notice the main.o, this got produced using the following command:
swiftc main.swift -emit-object
Thanx for the hints
I installed POCO using Homebrew.
Someone suggested using stdlibc++ instead, but when I do that, I get a bunch of std linking errors in addition to the POCO linking errors.
I also tried using g++ from Homebrew's gcc instead of Apple's g++, but that gives the same errors.
Makefile
CXX=g++
RM=rm -f
CXXFLAGS=-std=c++11 -Wall -O3 -I/usr/local/opt/openssl/include -I/usr/local/Cellar/poco/1.6.1/include
LDFLAGS=-L/usr/local/opt/openssl/lib -L/usr/local/Cellar/poco/1.6.1/lib
LDLIBS=-lPocoNet -lPocoFoundation
SRCS=eml.cc
OBJS=$(subst .cc,.o,$(SRCS))
all: eml
eml: $(OBJS)
$(CXX) $(CXXFLAGS) $(LDFLAGS) -o eml $(OBJS) $(LDLIBS)
%.o: %.c
$(CXX) $(CXXFLAGS) -c $< -o $#
clean:
$(RM) eml $(OBJS)
Errors
g++ -std=c++11 -stdlib=libc++ -Wall -O3 -I/usr/local/opt/openssl/include -I/usr/local/Cellar/poco/1.6.1/include -L/usr/local/opt/openssl/lib -L/usr/local/Cellar/poco/1.6.1/lib -o eml eml.o -lPocoNet -lPocoFoundation -lcrypto
Undefined symbols for architecture x86_64:
"Poco::Net::SSLManager::initializeClient(Poco::SharedPtr<Poco::Net::PrivateKeyPassphraseHandler, Poco::ReferenceCounter, Poco::ReleasePolicy<Poco::Net::PrivateKeyPassphraseHandler> >, Poco::SharedPtr<Poco::Net::InvalidCertificateHandler, Poco::ReferenceCounter, Poco::ReleasePolicy<Poco::Net::InvalidCertificateHandler> >, Poco::AutoPtr<Poco::Net::Context>)", referenced from:
_main in eml.o
"Poco::Net::SSLManager::instance()", referenced from:
_main in eml.o
"Poco::Net::initializeSSL()", referenced from:
_main in eml.o
"Poco::Net::uninitializeSSL()", referenced from:
_main in eml.o
"Poco::Net::SecureStreamSocket::SecureStreamSocket(Poco::Net::SocketAddress const&)", referenced from:
_main in eml.o
"Poco::Net::SecureStreamSocket::~SecureStreamSocket()", referenced from:
_main in eml.o
"Poco::Net::AcceptCertificateHandler::AcceptCertificateHandler(bool)", referenced from:
_main in eml.o
"Poco::Net::Context::Context(Poco::Net::Context::Usage, 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&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, Poco::Net::Context::VerificationMode, int, bool, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)", referenced from:
_main in eml.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: *** [eml] Error 1
You are not linking all the required libraries. All of the unresolved
symbols are defined in libPocoNetSSL. To install this library you must build the
full version, not the basic version version, of the POCO libraries.
If you consult the documentation of any of the POCO APIs it will tell you the libraries you need to link,
e.g. Poco::Net::SSLManager::initializeClient.
I installed Qt 5.0.0 (qt-mac-opensource-5.0.0-clang-offline.dmg) on a Mac OS X 10.7.5 and now I'm trying to compile a "Hello World" application using Qt Creator 2.6.1.
The build process complains about a directory not found: /Users/karlphillip/Qt5.0.0/5.0.0/clang_64/qtbase/lib , followed by several linking errors:
clang++ -c -pipe -mmacosx-version-min=10.6 -O2 -Wall -W -fPIE -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -I/Users/karlphillip/Qt5.0.0/5.0.0/clang_64/mkspecs/macx-clang -I. -I/Users/karlphillip/Qt5.0.0/5.0.0/clang_64/include -I/Users/karlphillip/Qt5.0.0/5.0.0/clang_64/include/QtGui -I/Users/karlphillip/Qt5.0.0/5.0.0/clang_64/lib/QtGui.framework/Versions/5/Headers -I/Users/karlphillip/Qt5.0.0/5.0.0/clang_64/include/QtCore -I/Users/karlphillip/Qt5.0.0/5.0.0/clang_64/lib/QtCore.framework/Versions/5/Headers -I. -I/System/Library/Frameworks/OpenGL.framework/Versions/A/Headers -I/System/Library/Frameworks/AGL.framework/Headers -o main.o main.cpp
clang++ -headerpad_max_install_names -mmacosx-version-min=10.6 -o hello_qt.app/Contents/MacOS/hello_qt main.o -F/Users/karlphillip/Qt5.0.0/5.0.0/clang_64/lib -framework QtGui -F/Users/karlphillip/Qt5.0.0/5.0.0/clang_64/qtbase/lib -framework QtCore -framework OpenGL -framework AGL
ld: warning: directory not found for option '-F/Users/karlphillip/Qt5.0.0/5.0.0/clang_64/qtbase/lib'
Undefined symbols for architecture x86_64:
"QApplication::QApplication(int&, char**, int)", referenced from:
_main in main.o
"QLabel::QLabel(QString const&, QWidget*, QFlags<Qt::WindowType>)", referenced from:
_main in main.o
"QWidget::show()", referenced from:
_main in main.o
"QPushButton::QPushButton(QString const&, QWidget*)", referenced from:
_main in main.o
"QApplication::exec()", referenced from:
_main in main.o
"QPushButton::~QPushButton()", referenced from:
_main in main.o
"QLabel::~QLabel()", referenced from:
_main in main.o
"QApplication::~QApplication()", referenced from:
_main in main.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: *** [hello_qt.app/Contents/MacOS/hello_qt] Error 1
It's important to note that the path /Users/karlphillip/Qt5.0.0/5.0.0/clang_64/qtbase/lib is not valid because the directory qtbase doesn't exist. The working path is /Users/karlphillip/Qt5.0.0/5.0.0/clang_64/lib. I'm not referring to qtbase anywhere in my project, so this is probably being added by qmake.
As it turns out, the invalid qtbase path thing is really a Qt bug originally reported at QTBUG-28336.
The linking problem is due to my project not linking with QtWidgets, which is something we are going to have to do starting in Qt5. This is accomplished by adding the following line to your .pro file:
QT += widgets
i had the same problem and to be honest im not shure how i managed it to solve.
i think/guess i copied the needed folders from the sources into the matching 'clang_64' folders and that does the job.
soo long zai
I've been developing a school project in XCode. The final product has to be submitted in source code with a makefile, so I wrote a makefile and to start compiling that way, to make sure I had a working copy. Here's my makefile:
all: main.o StackList.o world.o Farm.o
gcc main.o StackList.o world.o Farm.o -g -o Project1
main.o:
gcc -g -c main.cpp
StackList.o:
gcc -g -c Stacklist.cpp
world.cpp:
gcc -g -c world.cpp
Farm.cpp:
gcc -g -c Farm.cpp
clean:
rm *.o Project1
Compiling each of the object files works fine, but when it gets to "all," the linking step, it appears to not be aware of the standard library. I get "undefined symbols" error for everythin from "cin", to "basic_string", to "operator new".
I was under the impression that these things didn't need to be indicated directly, and in fact have not needed to do so in the past.
Any idea what might be happening?
EDIT:
If it helps, here's the start of the (very long) error message:
Undefined symbols for architecture x86_64:
"std::cin", referenced from:
_main in main.o
"std::cout", referenced from:
_main in main.o
Farm::print(int) in Farm.o
"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::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)", referenced from:
_main in main.o
"std::ios_base::Init::Init()", referenced from:
__static_initialization_and_destruction_0(int, int)in main.o
__static_initialization_and_destruction_0(int, int)in StackList.o
__static_initialization_and_destruction_0(int, int)in world.o
__static_initialization_and_destruction_0(int, int)in Farm.o
"std::ios_base::Init::~Init()", referenced from:
___tcf_0 in main.o
___tcf_0 in StackList.o
___tcf_0 in world.o
___tcf_0 in Farm.o
"operator new(unsigned long)", referenced from:
doStackSearch(std::basic_istream<char, std::char_traits<char> >*, std::list<Farm*, std::allocator<Farm*> >*&)in world.o
To link C++ code, you need to use the g++ command, not the gcc command.
When compiling, the gcc command knows that it's compiling C++ code because of the .cpp suffix (but it's a good idea to use the g++ command anyway).
When linking, the gcc command just sees a bunch of .o files. The g++ command differs from the gcc command in that it knows where to find the C++-specific libraries.
(The fact that the name gcc refers both to the command, which is usually used to compile C code, and the "GNU Compiler Collection" as a whole, can be a little confusing.)
You need to use g++ to compile and link C++ source code, not gcc.
Also, you can leave out all targets besides the first and last ones. make knows how to compile .cpp files to .o already -- you don't have to tell it how.
I know this is old, but if you are compiling and linking C++, you can specify the standard library yourself. Add -lstdc++ at end of your command.
gcc main.o StackList.o world.o Farm.o -g -o Project1
What in this command line do you think tells gcc to link in the C++ standard library? There are no C++ files being linked. You haven't specified a language. And you invoke the compilter as gcc.