shared_timed_mutex not available on OS X 10.11.2? - c++

I'm trying to play around with the new shared_timed_mutex structures from C++ 14 on OS X 10.11.2 using Eclipse CDT 4.5.0. Xcode is 7.2. I'm using GCC C++ with the following options:
-O0 -g3 -Wall -c -fmessage-length=0 -std=c++14
Her's what I get:
Invoking: MacOS X C++ Linker
g++ -o "MyProject" ./src/main.o
Undefined symbols for architecture x86_64:
"std::__1::shared_timed_mutex::shared_timed_mutex()", referenced from:
HashMap<int, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::hash<int> >::HashMap() 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)
Here's my clang version info:
Apple LLVM version 7.0.2 (clang-700.1.81)
Target: x86_64-apple-darwin15.2.0
Thread model: posix
I've searched my way through the web and found a couple of recommendations, for example this one on Reddit:
https://www.reddit.com/r/cpp_questions/comments/3ejfkr/is_c14s_stdshared_timed_mutex_available_on_os_x/?
This is very close to my problem, I've tried the suggestions, but I´m hoping, that I won´t have to do the manual libc++ download, but could stick with the standard libs shipped with my system.
Thank you!

For the past two years (as I write this) Apple has updated the libc++ headers for their tools releases, but not the libc++ sources. And libc++ implements std::shared_time_mutex both in <shared_mutex> and in shared_mutex.cpp.

According to Apple dev presentation the shared_timed_mutex will be available starting with macOS 10.12. See page 52

Related

Trying to use Boost C++ Library on MacOS

I've been trying for hours to get Boost C++ libraries working on MacOS 10.13.6.
I'm up-to-date with Xcode and Homebrew.
I used brew install boost to install boost and followed the Boost Getting Started instructions for help with compiling.
I've tried everything that I can think of and read every post I can find on StackOverflow about this.
I'm attempting to compile with:
g++ -std=c++17 -stdlib=libc++ -I /usr/local/opt/boost/include -L /usr/local/opt/boost/lib ass3.cpp -o ass3 -lboost_filesystem
and I get the following error message:
Undefined symbols for architecture x86_64: "boost::system::detail::generic_category_ncx()", referenced from: boost::system::generic_category()
in ass3-3dc386.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 haven't yet tried to install Boost from source.
If I exclude -std=c++17 the code will compile with a warning that I am using c++11 alias. As I get further into my project I'll be using c++17 specific features so I need to include this as far I as I know.
Compiler warning:
warning: alias declarations are a C++11 extension [-Wc++11-extensions]
What am I missing?

Undefined symbols:"basic_file" on my Mac OS using gcc

I am trying to compile a third-party tool. The command line looks like
gcc <many .o files and .a files> -g -lgmp -lgmpxx -lstdc++ -o bintool
which gives me this error:
Undefined symbols for architecture x86_64:
std::__basic_file<char>::is_open() const
For info, I find the __basic_file above is specified in
/usr/include/c++/4.2.1/bits/basic_file.h
But I do not know where it is actually implemented, and how to correctly link with it. Where should I get started for fixing this? I am on Mac OS. My 'gcc --version' gives:
Configured with: --prefix=/Library/Developer/CommandLineTools/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 7.0.2 (clang-700.1.81)
Target: x86_64-apple-darwin15.3.0
Thread model: posix
Any idea on how to fix the "undefined symbol" error? Thanks.

Undefined symbols for architecture x86_64: ... "_main", referenced from: implicit entry/start for main executable

Yak-shaving alert.
Although I am precluded from displaying any source code, I figure with a well-written post I may be able to provide enough info to get assistance. The steps I have tried below have all been garnered from other posts, and it's becoming a bit circular now.
I'm on OS X with the following:
MacBook-Pro-de-Pyderman:Metaphone3 Pyderman$ which g++
/usr/bin/g++
MacBook-Pro-de-Pyderman:Metaphone3 Pyderman$ arch
i386
MacBook-Pro-de-Pyderman:Metaphone3 Pyderman$ g++ --version
Configured with: --prefix=/Library/Developer/CommandLineTools/usr
--with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 6.0 (clang-600.0.57) (based on LLVM 3.5svn)
Target: x86_64-apple-darwin13.4.0
Thread model: posix
MacBook-Pro-de-Pyderman:Metaphone3 Pyderman$ gcc --version
Configured with: --prefix=/Library/Developer/CommandLineTools/usr
--with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 6.0 (clang-600.0.57) (based on LLVM 3.5svn)
Target: x86_64-apple-darwin13.4.0
Thread model: posix
MacBook-Pro-de-Pyderman:Metaphone3 Pyderman$ clang++ --version
Apple LLVM version 6.0 (clang-600.0.57) (based on LLVM 3.5svn)
Target: x86_64-apple-darwin13.4.0
Thread model: posix
MacBook-Pro-de-Pyderman:Metaphone3 Pyderman$ brew --config
HOMEBREW_VERSION: 0.9.5
ORIGIN: https://github.com/Homebrew/homebrew
HEAD: edcf1d119c4ca9d79d7147a684b7d74767cbb1f6
Last commit: 6 weeks ago
HOMEBREW_PREFIX: /usr/local
HOMEBREW_REPOSITORY: /usr/local
HOMEBREW_CELLAR: /usr/local/Cellar
HOMEBREW_BOTTLE_DOMAIN: https://homebrew.bintray.com
CPU: dual-core 64-bit penryn
OS X: 10.9.5-x86_64
Xcode: N/A
CLT: 6.2.0.0.1.1424975374
Clang: 6.0 build 600
X11: 2.7.7 => /opt/X11
System Ruby: 2.0.0-p481
Perl: /usr/bin/perl
Python: /Library/Frameworks/Python.framework/Versions/2.7/bin/python => /Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python
Ruby: /usr/bin/ruby => /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/ruby
Java: 1.6.0_65-b14-468
So I am given three files:
Metaphone3.cpp
Metaphone3ExampleCode.cpp
Metaphone3.h
I try to compile with g++:
g++ Metaphone3.cpp
I get:
Undefined symbols for architecture x86_64:
"_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 code 1 (use -v to see invocation)
gcc and clang++ report the same.
Adding -m32 has no affect.
g++ Metaphone3.cpp -I /usr/local/include has no effect
If I try:
g++ -Wall -c Metaphone3.cpp
This gets rid of the warning, and a Metaphone3.o and Metaphone get generated.
If I try to execute:
MacBook-Pro-de-Pyderman:Metaphone3 Pyderman$ ./Metaphone
-bash: ./Metaphone: Malformed Mach-o file
Some more research indicates that I may have missed a linking step. So:
gcc Metaphone3.o -o Metaphone3
But this brings me back to the original error.
Other posts then suggest dropping the -c flag, but it is this very flag that enabled me to get passed the error. So you can see how this is getting circular. As you may be gathering by now, I am a developer, but not a C++ developer, and coming from Python, the compilation world is a new one to me. Any and all assistance appreciated
An educated wild guess: main is in Metaphone3ExampleCode.cpp. You need to compile both, and link the resulting objects together.
Try
g++ -c Metaphone3.cpp
g++ -c Metaphone3ExampleCode.cpp
g++ -o Methaphone Metaphone3.o Metaphone3ExampleCode.o
or
g++ -o Methaphone Metaphone3.cpp Metaphone3ExampleCode.cpp
metaphone3.cpp should be compiled to an .so - it's a library and not an application
the example code is provided as a guide and is not intended to be compiled
if you make metaphone3.so, you'll need to make a c++ application yourself to link to it and test it
In case anyone else stumbles upon this in a google search, I received the same error above because of a simple typo: maint() instead of main()
smh

ACE fails at Linker in MAC OS X 10.9 (and higher)

I am trying to compile and run the following simple code in MAC OS X 10.9 with CLANG++:
#include "ACE_wrappers/ace/MEM_Stream.h"
#include <iostream>
int main()
{
std::cout << "Hello World" << std::endl;
ACE_MEM_Stream m(3);
m.close_reader();
return 0;
}
But I get the following error:
QAs-MacBook:aceTestLinking Moamen$ clang++ myTest.cpp
Undefined symbols for architecture x86_64:
"ace_os_main_i(int, char**)", referenced from:
_main in moamen-511a28.o
"ACE_SOCK::ACE_SOCK()", referenced from:
ACE_MEM_IO::ACE_MEM_IO() in moamen-511a28.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 compile line:
clang++ myTest.cpp
The CLANG Compiler version I am using:
QAs-MacBook:aceTestLinking Moamen$ clang++ --version
Apple LLVM version 6.0 (clang-600.0.54) (based on LLVM 3.5svn)
Target: x86_64-apple-darwin13.4.0
Thread model: posix
Notice - I have also tried to compile with "-std=c++11", "-stdlib=libstdc++", as in the following topic:
C++ linking error after upgrading to Mac OS X 10.9 / Xcode 5.0.1
but did not solve the issue.
Thanks,
Moamen
Thanks for the replies, after some investigation on Linux Ubuntu, I succeeded to compile the code with the following command g++ -o m.out myTest.cpp ACE_wrappers/lib/libACE.a -I ACE_wrappers/ -lpthread -ldl. Seems some default libs were missing!

Link error with boost::archive::test_oarchive using gcc OS X

I'm building a project that requires boost's text_oarchive function, and am getting a linker error when trying to build it.
I've installed Boost 1.55.0 on OS X 10.9
My compiler information is reported as:
$g++ --version
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 5.0 (clang-500.2.79) (based on LLVM 3.3svn)
Target: x86_64-apple-darwin13.0.0
Thread model: posix
The bootstrap.log file in the boost directory reports the "'darwin' toolset" was used.
however, when building from Eclipse, the following error is reported at the end of the build output:
"boost::archive::detail::basic_oarchive::~basic_oarchive()", referenced from:
::archive::detail::common_oarchive<boost::archive::text_oarchive>::~common_oarchive() in msgQueProducer.o
"typeinfo for boost::archive::archive_exception", referenced from:
void boost::serialization::throw_exception<boost::archive::archive_exception> (boost::archive::archive_exception const&) in msgQueProducer.o
"typeinfo for boost::archive::detail::basic_oarchive", referenced from:
typeinfo for boost::archive::detail::common_oarchive<boost::archive::text_oarchive> in msgQueProducer.o
"vtable for boost::archive::archive_exception", referenced from:
boost::archive::archive_exception::archive_exception(boost::archive::archive_exception const&) in msgQueProducer.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)
make: *** [msgQueProducer] Error 1
The project builds fine when the following single line of code removed from the project:
boost::archive::text_oarchive oa(oss);
I'm wondering if when I built the boost libraries I should have specified some architecture parameters (passing to the ./b2 tool something like "./b2 toolset=darwin cxxflags="-arch i386" address-model=64 architecture=x86 stage"). However, I'm building with another boost function used for interprocess messaging, and the project builds fine with it included.
The boost project includes I'm using are:
#include <boost/interprocess/ipc/message_queue.hpp>
#include <boost/archive/text_oarchive.hpp>
What do I need to do to use boost::text_oarchive on my OS X system?
Thanks in advance,
Walt
You need to link the boost-serialization library. Add -lboost_serialization to your LDFLAGS.