Why can't Eclipse find regex on Mac OSX? - regex

I'm using Eclipse Juno on OSX Mountain Lion and wanted to use std::regex, which I know is a C++11 only feature. When I #include <regex> the IDE says it doesn't exist. Maybe it's good to note that the header regex.h is present /usr/include/, though I see no specific library for it in /usr/lib/ or /usr/local/lib/, though I'm not aware if that's relevant. This is just a side project for fun so I'm not using a customized build system, just a regular C++ project in Eclipse.
I'm not real experienced when it comes to modifying a build process (other than setting include paths, libraries, etc.), especially when an IDE like Eclipse is driving it, but my assumption is that the compiler and linker (GCC G++) isn't configured for C++11, though I've tried various recommendations from SO and the Eclipse forums, like adding -std=c++11, but I just keep seeing output saying that they're unrecognized arguments.
I'm sure someone out there has dealt with this issue. Can anyone help? Thanks in advance.

On mac you have to use the flag:
-stdlib=libc++
and even then I believe generally only clang is updated enough(so use clang instead of gcc), if you've just been using the Xcode updates. You should also make sure that your Xcode command line tools are updated, because I would guess that is the compiler eclipse is using.

Related

Can I build wxwidgets with clang++?

There are walkthroughs to build wxwidgets with common compilers on windows, such as MSVC or MinGW, but there are no options for clang. I do have the other two compilers, but I dislike using Visual Studio for projects that are not C# or other .NET languages and I just don't like MinGW, nothing specifically. I use clang to compile, and I'd like to build wxwidgets with it, but I don't know if it would error or not, so would it work? I'm using windows, if not already clear. Thanks in advance.
You can definitely build wxGTK and wxMac under Linux and Mac respectively with clang and I think people did build wxMSW under Windows with it too, but it's a less commonly used compiler there, so your best bet would be to just try doing it. If you run into any problems, please free to open tickets on wxTrac, we do want to support clang under this platform as well.

How do I link a library in VSCode?

I'm trying to include curses.h and some functions from that lib (specifically detecting a keyboard hit without stopping), but whenever I try, it gives the error "symbols not found." I'm assuming that this is because the clang++ compiler sees curses.h as a C library. I've gathered I need to link curses.h, but I don't know how and I could not find any real guides.
I'm writing a program in C++ using VSCode and clang++ on a mac. Any help is appreciated.
For anyone else who has this problem- my clang version was outdated. It was installed, so after a brief check, I thought all was good. However, it was not able to compile (nor find some libs for some reason) the newer versions of C++. Installing the latest version of clang fixed all issues.

Link errors with AutoSeededRandomPool when using Xcode and libc++

Trying to develop simple c++ stuff in xcode for the first time. I haven't done c++ for a while, nor do I usually use a mac so bear with me if this is trivial.
I have simply grabbed the AutoSeededRandomPool example source from here: http://www.cryptopp.com/wiki/RandomNumberGenerator#AutoSeededRandomPool
I used macports to grab libcryptopp +universal (the non universal one didnt work either though), and I have added libcryptopp.a to the 'link binaries with libraries' build phase for my target.
During the build I get 22 errors, which you can see for yourself here: http://i.imgur.com/wIhEQot.jpg
Using xcode 4.6.2 on oldish Lion OS X macbook pro.
Have I missed something obvious here? Thanks for your help
You're not using the correct compiler — The project you mention states the requirement is:
Xcode 3.2.5,
Xcode 4.0 and GCC 4.2,
targeting Apple iOS
...It appears you're using clang++
http://www.cryptopp.com/#platforms
Also this says iOS, not OS X - That could certainly cause some issues as well. Why bother messing with this crypto library anyway? Use Apple's or one that was meant specifically to be used with OS X. It's of course your choice, but it certainly doesn't make it any easier going this route.
I have found the source of the problem was linking with the libc++ standard library rather than the more standard libstdc++ library. Xcode and Mac OS X targets were not a problem.
If I link against libstdc++ then the linking errors disappear. For future reference the giveaway seems to be the std::__1 namespacing visible in the errors, although with hindsight perhaps it should have been obvious that a library ported from linux would most likely be using the libstdc++ library.

boost asio giving You must add -D__USE_W32_SOCKETS to your compiler options on cygwin

I was trying to use the boost library first time. Using as an environment Eclipse 4.3 with CDT and as compiler gcc 3.4 and boost 1.53.
I was browsing various sites to find info on how to setup boost, but it doesn't seem to work. When I compile trying to include boost/asio.hpp I get the error:
You must add -D__USE_W32_SOCKETS to your compiler options
However, I don't want to use windows sockets, I want to use posix, so I don't really know what is wrong. As I need the project to run on HP-UX later, I dont want to get to Windows specific. If I use now windows sockets will the program later be easily portable to Unix, or are all the details encapsulated in boost, and I don't have to care anyway?
I tested a simple testprogram using FOREACH loop to confirm that boost itself works, and this is the case.
I also found this: https://svn.boost.org/trac/boost/ticket/7881 so does it mean that this problem is currently currently not supported, or am I doing something wrong?
It seems what you're trying to do is not supported by the library, the documentation states the following under supported platforms
The following platforms and compilers have been tested:
Win32 and Win64 using Visual C++ 7.1 and Visual C++ 8.0.
Win32 using MinGW.
Win32 using Cygwin. (__USE_W32_SOCKETS must be defined.)
Linux (2.4 or 2.6 kernels) using g++ 3.3 or later.
Solaris using g++ 3.3 or later.
Mac OS X 10.4 using g++ 3.3 or later.
added emphasis is mine. If that's not possible, you might try the patch suggested in the linked ticket. However, grepping through the source code I see several occurrences of #if !defined(BOOST_WINDOWS) && !defined(__CYGWIN__) so it's not obvious that simply patching io_service.hpp will resolve anything. You might try adding -U__CYGWIN__ to your CXXFLAGS, though the cygwin toolchain may not like that.
Full disclosure: I am not a Windows guy so hopefully someone else will chime in.
The libboost-devel package in the Cygwin distribution includes patches to not use Winsock on Cygwin in Boost.Asio. I suggest trying that in conjunction with the gcc4 packages, which provide more recent versions of GCC.

Problems with Eclipse C++ and Boost BGL

I'm having some problems to configure eclipse with the boost library. Actually my code compile without problems, but eclipse marks me some errors that the compiler does not.
I've added the path of the boost library in the includes of "paths and symbols" settings, and in fact eclipse recognizes the boost namespace, but I got several errors: for example
vector spanning_tree;
it reports as an invalid template arguments. Does anyone had my same problem?
I'm using the last version of eclipse and OS X as operating system.
Thank you
Although I haven't seen this particular problem, I know that in general, Eclipse CDT isn't quite as good as a full-fledged C++ compiler, and so it's not guaranteed to get every aspect of C++ correct.
Making sure that you're running the latest version of the Eclipse CDT is a good idea.
If you are running the latest version, then the Eclipse CDT developers would probably appreciate if it you report this as a bug.
As a last resort, you can disable the incorrect warnings (under Window, Preferences, C/C++, Code Analysis).