I'm trying to use adjacent_find in C++ as part of a maximum algorithm, but I'm not exactly succeeding. It worked in Xcode, mainly because it uses a different compiler. Now, I'm in Eclipse on a cygwin compiler, and it's not working. I already put the "-std=c++11" flag. Help?
This is the code I used:
if (adjacent_find(list.begin(), list.end(), not_equal_to<int>()) == list.end())
return -1; // all elements are equal
I can't check which version of Xcode I used because the computer is destroyed... sry. But I'm using Eclipse Cpp Neon version 4.6.2.
Related
I have code that I want to conditionally compile depending on the target SDK version, so that I can use newer features if possible. This can be done by checking the __MAC_OS_X_VERSION_MIN_REQUIRED macro, which tells us the target SDK version, in the source code.
Typically, performing conditional compilation on that macro suffices, and everything is nice and good. However, when targeting a newer SDK version, I would like to use features from a new library (specifically the UniformTypeIdentifiers library) that is not available on an older SDK version. This means that the target_link_libraries() in CMake has to account for this, i.e. link the new library if targeting a newer SDK version, and skip the new library otherwise.
I can't seem to find any way to figure out the target SDK version in CMake. What is the proper way to do this?
Things I have tried:
Checking CMAKE_OSX_DEPLOYMENT_TARGET. This flag is what CMake uses to pass the -mmacosx-version-min flag to clang, that makes it use a particular deployment target. However, it turns out that this may not necessarily be defined. When not defined, clang doesn't get the flag, but since clang is given something like -isysroot /Applications/Xcode-13.3.1.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.3.sdk, the framework sets __MAC_OS_X_VERSION_MIN_REQUIRED to something default (12.3), and so the source code is able to still perform conditional compilation.
Checking if the library exists by using find_library() (e.g. find_library(UNIFORMTYPEIDENTIFIERS_LIBRARY UniformTypeIdentifiers)). This does not work when users want to target a lower version (e.g. by setting CMAKE_OSX_DEPLOYMENT_TARGET), since the new library will still exist.
Essentially, I would like a way for CMake to figure out the deployment target that ultimately gets chosen (i.e. something equivalent to __MAC_OS_X_VERSION_MIN_REQUIRED), so that it can decide whether or not to link with the new library.
How should I do this?
Context:
I'm trying to resolve an issue in my library here.
I also have a testing branch set up to check CMAKE_OSX_DEPLOYMENT_TARGET and the compiler command in the CI builds: GitHub CI builds MacOS 10.15 (without the new library, with CMAKE_OSX_DEPLOYMENT_TARGET) and 11 (with the new library, with CMAKE_OSX_DEPLOYMENT_TARGET), and Circle CI builds MacOS 12 (with the new library, but without CMAKE_OSX_DEPLOYMENT_TARGET).
I couldn't find a way to determine this via some CMake variable, so I rolled by own compilation test for it:
include(CheckCXXSourceCompiles)
check_cxx_source_compiles(
"
#include <Availability.h>
#if !defined(__MAC_OS_X_VERSION_MIN_REQUIRED) || !defined(__MAC_11_0) || __MAC_OS_X_VERSION_MIN_REQUIRED < __MAC_11_0
static_assert(false);
#endif
int main() { return 0; }
"
NFD_USE_ALLOWEDCONTENTTYPES
)
This ensures full consistency with the check in the source code, at the cost of a slightly longer time to configure the build.
I am currently writing c++ code and compiling using Xcode. I was wondering: How can I find out which c++ compiler is Xcode 5 using?
I would like to know that to make sure that the program I am writing is compilable on other computers that don't necessarily use the same compiler.
Thanks in advance!
You can also check your target's build settings to see what the current setting is. However, Xcode 5 only uses the LLVM 5.0 compiler. GCC is no longer used.
https://developer.apple.com/technologies/tools/features.html
I have a C++11 project that uses Google Test, and it builds great in Linux. On a Mac, I am having more difficulty integrating it into my code base. The issue seems to be that while my code uses C++11, the Google code uses TR1. As a result, TR data structures like enum and unordered_set are included differently.
The Google Test samples build and run perfectly as provided. The samples also build just fine if I use clang++ instead of g++. (My code works only on clang++, so I use that to build.) Finally, Google's code also builds and runs if I use -std=c++11.
However, Google test does not build using clang++ on my mac if I use -stdlib=libc++. It reports that it cannot find tr1/tuple, which, of course, is true. This is a problem, because my code does not build if I use -stdlib=libstdc++ (or no stdlib argument).
Of course, I could switch all of my code over to the older standard. This, however, is extremely yuck. Is there a way to make these code bases live happily side-by-side on the Mac?
My code builds happily with Google test using g++ 4.6.3 on an Ubuntu 12.04 computer. The mac is running OSX 10.8.3. It's running g++ 4.2.1 and clang 4.2++.
Thanks for any help,
David
PS: I am somewhat new to C++, so forgive me if this is a foolish question.
Edit: Changed "OS/X" to "OSX." (Yes, I am that old.)
You can instruct Google test to use its own implementation of tr1::tuple
In cmake I use the following line to compile with "old" compilers:
add_definitions(-DGTEST_HAS_TR1_TUPLE=0)
I'm sure you can add it to your build system, it's a simple preprocessor definition.
You can look at include/gtest/internal/gtest-port.h for more options. GTEST_USE_OWN_TR1_TUPLE may be useful. Most of the parameters are correct with default values.
I have install g++-4.5, as I'm interested in the C++0x stuff (done by sudo port install gcc45). Now I've made sure it's my default compiler (using gcc_select) and all of my Makefile projects do just fine compiling with 4.5.
Now I'm starting a project in xCode 4. How do I get the same C++0x features from within xCode, a.k.a. tell xCode to use g++-4.5?
These two bloggers describe hacking together an Xcode plugin to use one's own build of clang. I imagine you could use the same thing but substitute gcc 4.5's path.
http://belkadan.com/blog/2011/07/Using-Clang-from-SVN-in-Xcode/
http://shapeof.com/archives/2010/01/using_the_latest_llvm_with_xcode.html
I've been meaning to try, and found your question in my research.
My specs:
OS: Ubuntu 10.04 LTS amd64
fpc: 2.4.0
lazarus: 0.9.28
I'm trying to compile a WebLaz project just by creating one and then compiling.
Somehow the compiler gets all lost when determinig witch httpd and fpapache Units to use.
I've found similar problems in the forums:
mod_helloworld.lpr Can't find fpapache Unit ...
I NEED HELP with fpweb ...
After trying some of the solutions provided there I'm still at this point:
Project compiles fine if I only have httpd22 under the Compiled units and the Source for the packages. Alas it then completely fails to link.
With the original fpc/lazarus folder structure (Having all of HTTPD13, HTTPD20 and HTTPD22 untouched on both locations, units and source) the compiler complains that checksum of httpd has changed and the fails to find fpapache's source.
It finds httpd.pas under httpd20 but then it only works with folders for 2.2
I'm completely lost as how to compile this using the WebLaz component, what am I missing?
Probably you need to select the version you want, and then rebuild the relevant lazarus parts, so that the pkgs get build with the then selected apache.
Afaik the selection of the httpd daemons is simply changing order, it doesn't mean that all versions are supported at once, like e.g. mysqlconnection does.
From what I could investigate from the, very verbose, output using the Test button on the "Compiler Options" none for these option are defined:
FPCAPACHE_1_3
FPCAPACHE_2_0
So this means that in: /etc/fpc.cfg
#IFDEF FPCAPACHE_1_3
-Fu/usr/lib/fpc/$fpcversion/units/$fpctarget/httpd13/
#ELSE
#IFDEF FPCAPACHE_2_0
-Fu/usr/lib/fpc/$fpcversion/units/$fpctarget/httpd20/
#ELSE
-Fu/usr/lib/fpc/$fpcversion/units/$fpctarget/httpd22/
#ENDIF
#ENDIF
The test will revert to httpd22 by default.
None the less, having:
/usr/lib/fpc/2.4.0/units/x86_64-linux/httpd20
/usr/lib/fpc/2.4.0/units/x86_64-linux/httpd22
in the compiler's path to compiled units it means that it will find httpd20 first.
This means it will try to load the 2.0 version and not the 2.2 version of the compiled units.
So the first solution is to delete/move the 1. folder from the system.
This will let you compile, but alas it will not link on a 64 bit system (I'm testing on a AMD64 system so I'm not going to presume it works elsewhere).
The process ends with a hint, to add -fPIC to the compiler options.
If you go to Project->Compiler Options...->Other on the lower TextBox you can add it.
Voila, it's working.