getting jsoncpp to compile

Hello,

I am having a hard time getting jsoncpp installed and compiled on freebsd. Below is a very small program just to 'get it working with bare bones'. I try to use the ports and I get a segmentation fault. I try to compile from source and get a ton of errors. Thanks for any help you can give

install jsoncpp port
Code:
pkg install jsoncpp

this is the code i used for a small example
Code:
#include <iostream>

#include <json/json.h>
#include <json/reader.h>
#include <json/writer.h>
#include <json/value.h>

using namespace std;

int main()
{
    Json::Value root;
    return 0;
}

compile and link
Code:
g++ -Wall -std=c++11 -fexceptions -g -I/usr/home/libs/jsoncpp-master/include/ -I/usr/local/include/ -c "test3.cpp" -o test3.o
g++ -L/usr/local/lib/ -o "test3" test3.o   -lpthread -ljsoncpp

run it and core dump
Code:
$ ./test3
Segmentation fault (core dumped)



so then I download from source and compile it
https://github.com/open-source-parsers/jsoncpp/archive/master.zip

instructions say to use these commands once it is unpacked
Code:
cd jsoncpp/
LIB_TYPE=shared
meson --buildtype debug --default-library static . build-static
ninja -v -C build-static test
cd build-static
sudo ninja install

compile it with the next dirs
Code:
g++ -Wall -std=c++11 -fexceptions -g -I/usr/home/libs/jsoncpp-master/include/ -I/usr/local/include/ -c "test3.cpp" -o test3.o
g++ -L/usr/lib/ -L/lib/ -L/usr/local/lib/ -o "test3" test3.o   -lpthread /usr/home/libs/jsoncpp-master/build-static/libjsoncpp.a


and i get these errors (truncated but the real errors are 10x longer) The forum has a char limit on how much you can post
Code:
/usr/home/libs/jsoncpp-master/build-static/libjsoncpp.a(src_lib_json_json_value.cpp.o): In function `_ZNSt3__112basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEE6__initIPKcEENS_9enable_ifIXsr21__is_forward_iteratorIT_EE5valueEvE4typeESA_SA_':
/usr/include/c++/v1/string:1802: undefined reference to `std::__1::__basic_string_common<true>::__throw_length_error() const'
/usr/home/libs/jsoncpp-master/build-static/libjsoncpp.a(src_lib_json_json_value.cpp.o): In function `std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::__init(char const*, unsigned long)':
/usr/include/c++/v1/string:1523: undefined reference to `std::__1::__basic_string_common<true>::__throw_length_error() const'
/usr/home/libs/jsoncpp-master/build-static/libjsoncpp.a(src_lib_json_json_value.cpp.o): In function `ValueIterator':
/usr/home/libs/jsoncpp-master/build-static/../src/lib_json/json_valueiterator.inl:156: undefined reference to `std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::~basic_string()'
/usr/home/libs/jsoncpp-master/build-static/libjsoncpp.a(src_lib_json_json_value.cpp.o): In function `Exception':
/usr/home/libs/jsoncpp-master/build-static/../src/lib_json/json_value.cpp:194: undefined reference to `std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::basic_string(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)'
/usr/home/libs/jsoncpp-master/build-static/libjsoncpp.a(src_lib_json_json_value.cpp.o): In function `~Exception':
/usr/home/libs/jsoncpp-master/build-static/../src/lib_json/json_value.cpp:197: undefined reference to `std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::~basic_string()'
/usr/home/libs/jsoncpp-master/build-static/libjsoncpp.a(src_lib_json_json_value.cpp.o): In function `std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::__init(char const*, unsigned long)':
/usr/include/c++/v1/string:1523: undefined reference to `std::__1::__basic_string_common<true>::__throw_length_error() const'
/usr/home/libs/jsoncpp-master/build-static/libjsoncpp.a(src_lib_json_json_value.cpp.o): In function `Json::Value::CommentInfo::setComment(char const*, unsigned long)':
/usr/home/libs/jsoncpp-master/build-static/../src/lib_json/json_value.cpp:238: undefined reference to `std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::~basic_string()'
/usr/home/libs/jsoncpp-master/build-static/libjsoncpp.a(src_lib_json_json_value.cpp.o): In function `ios_base':
/usr/include/c++/v1/ios:336: undefined reference to `vtable for std::__1::ios_base'
/usr/home/libs/jsoncpp-master/build-static/libjsoncpp.a(src_lib_json_json_value.cpp.o): In function `basic_ios':
/usr/include/c++/v1/ios:650: undefined reference to `vtable for std::__1::basic_ios<char, std::__1::char_traits<char> >'
/usr/home/libs/jsoncpp-master/build-static/libjsoncpp.a(src_lib_json_json_value.cpp.o): In function `std::__1::basic_ios<char, std::__1::char_traits<char> >::init(std::__1::basic_streambuf<char, std::__1::char_traits<char> >*)':
/usr/include/c++/v1/ios:687: undefined reference to `std::__1::ios_base::init(void*)'
/usr/home/libs/jsoncpp-master/build-static/libjsoncpp.a(src_lib_json_json_value.cpp.o): In function `basic_stringbuf':
/usr/include/c++/v1/sstream:211: undefined reference to `std::__1::basic_streambuf<char, std::__1::char_traits<char> >::basic_streambuf()'
/usr/include/c++/v1/sstream:246: undefined reference to `std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::~basic_string()'
/usr/include/c++/v1/sstream:247: undefined reference to `std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::~basic_string()'
/usr/include/c++/v1/sstream:247: undefined reference to `std::__1::basic_streambuf<char, std::__1::char_traits<char> >::~basic_streambuf()'
/usr/home/libs/jsoncpp-master/build-static/libjsoncpp.a(src_lib_json_json_value.cpp.o): In function `basic_ostringstream':
/usr/include/c++/v1/sstream:785: undefined reference to `std::__1::basic_ostream<char, std::__1::char_traits<char> >::~basic_ostream()'
/usr/include/c++/v1/sstream:785: undefined reference to `std::__1::basic_ios<char, std::__1::char_traits<char> >::~basic_ios()'
/usr/home/libs/jsoncpp-master/build-static/libjsoncpp.a(src_lib_json_json_value.cpp.o): In function `basic_stringbuf':
/usr/include/c++/v1/sstream:246: undefined reference to `std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::~basic_string()'
/usr/home/libs/jsoncpp-master/build-static/libjsoncpp.a(src_lib_json_json_value.cpp.o): In function `Json::Value::CommentInfo::setComment(char const*, unsigned long)':
/usr/home/libs/jsoncpp-master/build-static/../src/lib_json/json_value.cpp:239: undefined reference to `std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::~basic_string()'
/usr/home/libs/jsoncpp-master/build-static/libjsoncpp.a(src_lib_json_json_value.cpp.o): In function `std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::__init(char const*, unsigned long)':
/usr/include/c++/v1/string:1523: undefined reference to `std::__1::__basic_string_common<true>::__throw_length_error() const'
/usr/home/libs/jsoncpp-master/build-static/libjsoncpp.a(src_lib_json_json_value.cpp.o): In function `Json::duplicateStringValue(char const*, unsigned long)':
/usr/home/libs/jsoncpp-master/build-static/../src/lib_json/json_value.cpp:107: undefined reference to `std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::~basic_string()'
/usr/home/libs/jsoncpp-master/build-static/libjsoncpp.a(src_lib_json_json_value.cpp.o): In function `std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::__init(char const*, unsigned long)':
/usr/include/c++/v1/string:1523: undefined reference to `std::__1::__basic_string_common<true>::__throw_length_error() const'
/usr/home/libs/jsoncpp-master/build-static/libjsoncpp.a(src_lib_json_json_value.cpp.o): In function `Json::Value::CZString::operator<(Json::Value::CZString const&) const':
/usr/home/libs/jsoncpp-master/build-static/../src/lib_json/json_value.cpp:317: undefined reference to `std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::~basic_string()'
/usr/home/libs/jsoncpp-master/build-static/libjsoncpp.a(src_lib_json_json_value.cpp.o): In function `std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::__init(char const*, unsigned long)':
/usr/include/c++/v1/string:1523: undefined reference to `std::__1::__basic_string_common<true>::__throw_length_error() const'
/usr/home/libs/jsoncpp-master/build-static/libjsoncpp.a(src_lib_json_json_value.cpp.o): In function `Json::Value::CZString::operator==(Json::Value::CZString const&) const':
/usr/home/libs/jsoncpp-master/build-static/../src/lib_json/json_value.cpp:331: undefined reference to `std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::~basic_string()'
/usr/home/libs/jsoncpp-master/build-static/libjsoncpp.a(src_lib_json_json_value.cpp.o): In function `ios_base':
/usr/include/c++/v1/ios:336: undefined reference to `vtable for std::__1::ios_base'
/usr/home/libs/jsoncpp-master/build-static/libjsoncpp.a(src_lib_json_json_value.cpp.o): In function `basic_ios':
/usr/include/c++/v1/ios:650: undefined reference to `vtable for std::__1::basic_ios<char, std::__1::char_traits<char> >'
/usr/home/libs/jsoncpp-master/build-static/libjsoncpp.a(src_lib_json_json_value.cpp.o): In function `std::__1::basic_ios<char, std::__1::char_traits<char> >::init(std::__1::basic_streambuf<char, std::__1::char_traits<char> >*)':
/usr/include/c++/v1/ios:687: undefined reference to `std::__1::ios_base::init(void*)'
/usr/home/libs/jsoncpp-master/build-static/libjsoncpp.a(src_lib_json_json_value.cpp.o): In function `basic_stringbuf':
/usr/include/c++/v1/sstream:211: undefined reference to `std::__1::basic_streambuf<char, std::__1::char_traits<char> >::basic_streambuf()'
/usr/include/c++/v1/sstream:246: undefined reference to `std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::~basic_string()'
/usr/include/c++/v1/sstream:247: undefined reference to `std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::~basic_string()'
/usr/include/c++/v1/sstream:247: undefined reference to `std::__1::basic_streambuf<char, std::__1::char_traits<char> >::~basic_streambuf()'
/usr/home/libs/jsoncpp-master/build-static/libjsoncpp.a(src_lib_json_json_value.cpp.o): In function `basic_ostringstream':
/usr/include/c++/v1/sstream:785: undefined reference to `std::__1::basic_ostream<char, std::__1::char_traits<char> >::~basic_ostream()'
/usr/include/c++/v1/sstream:785: undefined reference to `std::__1::basic_ios<char, std::__1::char_traits<char> >::~basic_ios()'
/usr/home/libs/jsoncpp-master/build-static/libjsoncpp.a(src_lib_json_json_value.cpp.o): In function `basic_stringbuf':
/usr/include/c++/v1/sstream:246: undefined reference to `std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::~basic_string()'
/usr/home/libs/jsoncpp-master/build-static/libjsoncpp.a(src_lib_json_json_value.cpp.o): In function `Value':
/usr/home/libs/jsoncpp-master/build-static/../src/lib_json/json_value.cpp:411: undefined reference to `std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::~basic_string()'
/usr/home/libs/jsoncpp-master/build-static/libjsoncpp.a(src_lib_json_json_value.cpp.o): In function `ios_base':
/usr/include/c++/v1/ios:336: undefined reference to `vtable for std::__1::ios_base'
/usr/home/libs/jsoncpp-master/build-static/libjsoncpp.a(src_lib_json_json_value.cpp.o): In function `basic_ios':
/usr/include/c++/v1/ios:650: undefined reference to `vtable for std::__1::basic_ios<char, std::__1::char_traits<char> >'
/usr/home/libs/jsoncpp-master/build-static/libjsoncpp.a(src_lib_json_json_value.cpp.o): In function `std::__1::basic_ios<char, std::__1::char_traits<char> >::init(std::__1::basic_streambuf<char, std::__1::char_traits<char> >*)':
/usr/include/c++/v1/ios:687: undefined reference to `std::__1::ios_base::init(void*)'
/usr/home/libs/jsoncpp-master/build-static/libjsoncpp.a(src_lib_json_json_value.cpp.o): In function `basic_stringbuf':
/usr/include/c++/v1/sstream:211: undefined reference to `std::__1::basic_streambuf<char, std::__1::char_traits<char> >::basic_streambuf()'
/usr/include/c++/v1/sstream:246: undefined reference to `std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::~basic_string()'
/usr/include/c++/v1/sstream:247: undefined reference to `std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::~basic_string()'
/usr/include/c++/v1/sstream:247: undefined reference to `std::__1::basic_streambuf<char, std::__1::char_traits<char> >::~basic_streambuf()'
/usr/home/libs/jsoncpp-master/build-static/libjsoncpp.a(src_lib_json_json_value.cpp.o): In function `basic_ostringstream':
/usr/include/c++/v1/sstream:785: undefined reference to `std::__1::basic_ostream<char, std::__1::char_traits<char> >::~basic_ostream()'
/usr/include/c++/v1/sstream:785: undefined reference to `std::__1::basic_ios<char, std::__1::char_traits<char> >::~basic_ios()'
/usr/home/libs/jsoncpp-master/build-static/libjsoncpp.a(src_lib_json_json_value.cpp.o): In function `basic_stringbuf':
/usr/include/c++/v1/sstream:246: undefined reference to `std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::~basic_string()'
/usr/home/libs/jsoncpp-master/build-static/libjsoncpp.a(src_lib_json_json_value.cpp.o): In function `Json::duplicateAndPrefixStringValue(char const*, unsigned int)':
/usr/home/libs/jsoncpp-master/build-static/../src/lib_json/json_value.cpp:124: undefined reference to `std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::~basic_string()'
/usr/home/libs/jsoncpp-master/build-static/libjsoncpp.a(src_lib_json_json_value.cpp.o): In function `std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::__init(char const*, unsigned long)':
/usr/include/c++/v1/string:1523: undefined reference to `std::__1::__basic_string_common<true>::__throw_length_error() const'
/usr/home/libs/jsoncpp-master/build-static/libjsoncpp.a(src_lib_json_json_value.cpp.o): In function `Json::duplicateAndPrefixStringValue(char const*, unsigned int)':
/usr/home/libs/jsoncpp-master/build-static/../src/lib_json/json_value.cpp:130: undefined reference to `std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::~basic_string()'
/usr/home/libs/jsoncpp-master/build-static/libjsoncpp.a(src_lib_json_json_value.cpp.o): In function `std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::__init(char const*, unsigned long)':
/usr/include/c++/v1/string:1523: undefined reference to `std::__1::__basic_string_common<true>::__throw_length_error() const'
/usr/home/libs/jsoncpp-master/build-static/libjsoncpp.a(src_lib_json_json_value.cpp.o): In function `Json::Value::operator<(Json::Value const&) const':
/usr/home/libs/jsoncpp-master/build-static/../src/lib_json/json_value.cpp:536: undefined reference to `std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::~basic_string()'
/usr/home/libs/jsoncpp-master/build-static/libjsoncpp.a(src_lib_json_json_value.cpp.o): In function `std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::__init(char const*, unsigned long)':
/usr/include/c++/v1/string:1523: undefined reference to `std::__1::__basic_string_common<true>::__throw_length_error() const'
/usr/home/libs/jsoncpp-master/build-static/libjsoncpp.a(src_lib_json_json_value.cpp.o): In function `Json::Value::operator==(Json::Value const&) const':
/usr/home/libs/jsoncpp-master/build-static/../src/lib_json/json_value.cpp:592: undefined reference to `std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::~basic_string()'
/usr/home/libs/jsoncpp-master/build-static/libjsoncpp.a(src_lib_json_json_value.cpp.o): In function `ios_base':
/usr/include/c++/v1/ios:336: undefined reference to `vtable for std::__1::ios_base'
/usr/home/libs/jsoncpp-master/build-static/libjsoncpp.a(src_lib_json_json_value.cpp.o): In function `basic_ios':
/usr/include/c++/v1/ios:650: undefined reference to `vtable for std::__1::basic_ios<char, std::__1::char_traits<char> >'
/usr/home/libs/jsoncpp-master/build-static/libjsoncpp.a(src_lib_json_json_value.cpp.o): In function `std::__1::basic_ios<char, std::__1::char_traits<char> >::init(std::__1::basic_streambuf<char, std::__1::char_traits<char> >*)':
/usr/include/c++/v1/ios:687: undefined reference to `std::__1::ios_base::init(void*)'
/usr/home/libs/jsoncpp-master/build-static/libjsoncpp.a(src_lib_json_json_value.cpp.o): In function `basic_stringbuf':
/usr/include/c++/v1/sstream:211: undefined reference to `std::__1::basic_streambuf<char, std::__1::char_traits<char> >::basic_streambuf()'
/usr/include/c++/v1/sstream:246: undefined reference to `std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::~basic_string()'
/usr/include/c++/v1/sstream:247: undefined reference to `std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::~basic_string()'
/usr/include/c++/v1/sstream:247: undefined reference to `std::__1::basic_streambuf<char, std::__1::char_traits<char> >::~basic_streambuf()'
/usr/home/libs/jsoncpp-master/build-static/libjsoncpp.a(src_lib_json_json_value.cpp.o): In function `basic_ostringstream':
/usr/include/c++/v1/sstream:785: undefined reference to `std::__1::basic_ostream<char, std::__1::char_traits<char> >::~basic_ostream()'
/usr/include/c++/v1/sstream:785: undefined reference to `std::__1::basic_ios<char, std::__1::char_traits<char> >::~basic_ios()'
/usr/home/libs/jsoncpp-master/build-static/libjsoncpp.a(src_lib_json_json_value.cpp.o): In function `basic_stringbuf':
/usr/include/c++/v1/sstream:246: undefined reference to `std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::~basic_string()'
/usr/home/libs/jsoncpp-master/build-static/libjsoncpp.a(src_lib_json_json_value.cpp.o): In function `Json::Value::asCString() const':
/usr/home/libs/jsoncpp-master/build-static/../src/lib_json/json_value.cpp:609: undefined reference to `std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::~basic_string()'
/usr/home/libs/jsoncpp-master/build-static/libjsoncpp.a(src_lib_json_json_value.cpp.o): In function `std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::__init(char const*, unsigned long)':
/usr/include/c++/v1/string:1523: undefined reference to `std::__1::__basic_string_common<true>::__throw_length_error() const'
/usr/include/c++/v1/string:1523: undefined reference to `std::__1::__basic_string_common<true>::__throw_length_error() const'
/usr/include/c++/v1/string:1523: undefined reference to `std::__1::__basic_string_common<true>::__throw_length_error() const'
/usr/include/c++/v1/string:1523: undefined reference to `std::__1::__basic_string_common<true>::__throw_length_error() const'
/usr/home/libs/jsoncpp-master/build-static/libjsoncpp.a(src_lib_json_json_value.cpp.o): In function `ios_base':
/usr/include/c++/v1/ios:336: undefined reference to `vtable for std::__1::ios_base'
/usr/home/libs/jsoncpp-master/build-static/libjsoncpp.a(src_lib_json_json_value.cpp.o): In function `basic_ios':
/usr/include/c++/v1/ios:650: undefined reference to `vtable for std::__1::basic_ios<char, std::__1::char_traits<char> >'
/usr/home/libs/jsoncpp-master/build-static/libjsoncpp.a(src_lib_json_json_value.cpp.o): In function `std::__1::basic_ios<char, std::__1::char_traits<char> >::init(std::__1::basic_streambuf<char, std::__1::char_traits<char> >*)':

truncated since there is a limit on how much you can post
 
Why download from Github? Try devel/jsoncpp instead. That will also build jsoncpp but this time with all the required patches made by the port maintainer in order to ensure that it will actually build.
 
Why download from Github? Try devel/jsoncpp instead. That will also build jsoncpp but this time with all the required patches made by the port maintainer in order to ensure that it will actually build.
sorry for my ignorance but I though thats what i was doing when i did
#pkg install jsoncpp
??


I did these commands from this guide https://www.freebsd.org/doc/handbook/ports-using.html
Code:
# portsnap fetch
# portsnap extract
# portsnap fetch
# portsnap update
# portsnap fetch update

then i did
Code:
pkg install jsoncpp

Code:
whereis jsoncpp
jsoncpp: /usr/ports/devel/jsoncpp

Code:
cd /usr/ports/devel/jsoncpp
make install
did I do that right?
 
now when I go to compile
Code:
g++ -Wall -std=c++11 -fexceptions -g  -I/usr/local/include/ -c "test3.cpp" -o test3.o
g++ -L/usr/local/lib/ -o "test3" test3.o  /usr/local/lib/libjsoncpp.so

Code:
$ ./test3
Segmentation fault (core dumped)

Code:
#include <iostream>

#include </usr/local/include/jsoncpp/json/json.h>
#include </usr/local/include/jsoncpp/json/value.h>

using namespace std;

int main()
{
    Json::Value root;
    return 0;
}
 
sorry for my ignorance but I though thats what i was doing when i did
#pkg install jsoncpp
??
Not quite.

If you use pkg-install(8) then you're not building anything yourself; you're using pre-compiled packages which you download from a software repository. So you don't even need to use portsnap because you're not using the ports collection.

For general use this could be the best solution because you don't have to bother yourself with configuring and building the packages.

If you do want to build software yourself you'd need the make command. So to build devel/jasoncpp you'd use:
Code:
unicron:/home/peter $ cd /usr/ports/devel/jsoncpp/
unicron:/usr/ports/devel/jsoncpp $ make config
===> No options to configure
unicron:/usr/ports/devel/jsoncpp $ su
unicron:/usr/ports/devel/jsoncpp # make install clean
These are all the steps you'd need to actually build the port yourself (all apart from the make config command obviously).

But do keep in mind that there's a major difference between building/installing a port (normally done using # make install clean and installing a (pre-compiled) package which is done using # pkg install. However, in the end both have roughly the same result: the installation of the software. One will be optimized (and possibly configured) for your system while the other uses default options.

I did these commands from this guide https://www.freebsd.org/doc/handbook/ports-using.html
Code:
# portsnap fetch
# portsnap extract
# portsnap fetch
# portsnap update
# portsnap fetch update
That's also a bit too much. Why would you need to update your ports collection right after you installed it? It's usually best to update every day or maybe every week. So after you installed the ports collection there's no direct need to update it right away.

But I do agree with unitrunker: use clang++ instead of g++. The difference is that Clang is the default compiler for FreeBSD so if you install a library using the ports collection then you can be sure that it will be set up for optimal usage with Clang. g++ is something which you installed manually and which isn't part of FreeBSD, so there are also not much guarantees that it will actually work. For all I know it could even be using totally different include paths.
 
This works? but what is the difference?
On FreeBSD we link everything with libc++ and gcc always links with its own libstdc++. libc++ and libstdc++ are incompatible with each other. What happens is that jsoncpp installed from pkg or from ports is linked with libc++ (by virtue of being compiled with clang++) and your program (compiled with g++) will be linked to libstdc++. Now your program is linked to both libc++ via libjsoncpp.so and libstdc++ leading to crashes. Check ldd(1) output on your test program.

You can goad g++ into linking with libc++ via this hack. This is what the ports tree supports via USES=compiler:gcc-c++11-lib in case you absolutely must compile with g++ but also want to build and link with libc++. I don't think gcc has an explicit option for it:
Code:
mkdir -p gcchack
ln -sf /usr/lib/libc++.so gcchack/libstdc++.so
g++ -Wall -std=c++11 -fexceptions -nostdinc++ -isystem /usr/include/c++/v1 -g  -I/usr/local/include/ -c test3.cpp -o test3.o
g++ -Lgcchack -L/usr/local/lib/ -o test3 test3.o  /usr/local/lib/libjsoncpp.so
 
Back
Top