I'm having issues with XCode, LLVM and the _DEBUG definition. Or more specifically it seems to be something with underscore.
This is the second time I'm getting an error like this. This time Im compiling against PhysX lib.
/Library/Frameworks/PhysX.framework/Versions/3.2.1/include/foundation/PxPreprocessor.h:316:35:
Expected value in expression
The line it's complaining about:
#if !defined(PX_CHECKED) && _DEBUG
And it points at right after the _DEBUG. If I remove the underscore it compiles fine (I did that on a similiar library last time as well, see http://www.ogre3d.org/forums/viewtopic.php?f=2&t=78990). But now Im feeling uneasy about this error. What is causing it and what does it mean?
Settings:
Dialect: C++11, libc++ (Tried different ones, like GNUC++11
Max OSX 10.8
XCode 5
LLVM 5.0
Names that begin with an underscore are reserved for the implementation. Instead, use names that don't begin with an underscore unless you are specifically trying to access some implementation-specific feature.
Use defined() on implementation specific macros:
#if !defined(PX_CHECKED) && defined(_DEBUG)
If there's some reason you are expecting this to work, you haven't explained what it is. There is no reason this should work. What are you expecting it to do?
Related
I've got the problem that my program will compile with g++10.2 and c++11 activated through cmake. but it will not compile with arduino dues arm-none-eabi-g++.exe compiler which also has c++11. The failure occurs because of one line that needs to be added for the arm compiler, but when I add that line to g++10.2 it won't compile.
So I need an #ifdef or some alternative to activate and deactivate the line specific for the compiler.
Like Deumaudit said in the comments:
Try to use __arm__, __aarch64__ or __ARM_ARCH macro
You'll probably be ok if you use #ifdef __arm__ or even #if defined(__arm__) || defined(__aarch64__)
If you're planning to add more supported platforms to your program, it might be a good idea to define some macros when building for a specific platform. I have my own _MY_APP_ARM macro defined in my CMakeLists.txt:
if(${CMAKE_SYSTEM_PROCESSOR} MATCHES "arm")
add_definitions(-D_MY_APP_ARM)
endif()
Which I can then use as #ifdef _MY_APP_ARM
My program compiles fine, but Netbeans tells me "Unable to resolve identifier to_string."
I tried everything in "Netbeans 7.2 shows "Unable to resolve identifier" , although build is successful" and I set the "C++ standard" to "C++11" in the code assistance options.
This is the only function giving this problem so far. It is however also the first C++11 feature I am using, which leads me to believe it has something to do with Netbeans not understanding that I am using C++11, although I specify it explicitly in the code assistance menu.
Minimal example:
#include <string>
int main() {
std::to_string(1);
}
EDIT: the same problem arises where using nullptr
EDIT2: I suddenly realized it might be important to mention that I do not use a generated Makefile, but SCons.
I know this question is seven months old but since it came up as the second result to a google search I'll tell the answer I came up with. For Netbeans at least. Go to your project properties and make sure you have you "C Compiler"->"C Standard" set to C11, and your "C++ compiler"->"C++ Standard" set to C++11. You have to set BOTH or it will still give false errors!
This will solve the problem:
Right click on "Project".
Select "Code Assistance".
Clean C/C++ cache.
Restart IDE.
Autocomplete and sometimes even syntax highlighting are always faulty with C++. The more you go in depth with C++ and C++11, the more Eclipse and Netbeans will start underlining everything with a red wavy line. Some of my (correct and perfectly compiling) programs are a huge red wavy line. I suggest you disable error markers altogether and you keep autocomplete, but in many cases it just won't work and you have to make the best of it.
I had the same situation. This was occurred because I used .c file instead of .cpp
for Netbeans 8.2 (on Linux) only the following worked for me: Tools -> Options -> Code Assistance -> Macro Definitions:
change:__cplusplus=199711L
to:__cplusplus=201402L
for C++14
or to __cplusplus=201103L
for C++11
I did all the above but what did the trick for me was recognizing that the Makefile had g++ rather than g++ -std=c++11.
To resolve c++17 related 'Unable to resolve identifier' in latest netbeans 8.2 or 9 version, one may need to set the macro definition __cplusplus=201703L as the default C++14 standard macro definition unable to resolve those unexpected error messages appeared in the editor.
I am using QT Creator to make a C++ program on Ubuntu. The program I had written was compiling fine, until I decided to start using C++11 rather than C++98 (which is the default in QT Creator). I am using my own cmake file, rather than qmake, and so to do this, I included the following line in my CMakeLists.txt file:
set(CMAKE_CXX_FLAGS "-std=c++0x")
Now, part of my code has the following (which was not written by me):
#if (linux && (i386 || __x86_64__))
# include "Linux-x86/OniPlatformLinux-x86.h"
#elif (linux && __arm__)
# include "Linux-Arm/OniPlatformLinux-Arm.h"
#else
# error Unsupported Platform!
#endif
After transferring to C++11, I get an error at the line error Unsupported Platform!. This is because, from what I can see, the variable linux is not defined anywhere, although the variable __x86_64__ is defined.
Therefore, I have two questions:
1) Why is the variable linux not defined, even though I am using Linux?
2) How can I tell C++11 to ignore this error?
Thanks.
The identifier linux is not reserved. A conforming compiler may not predefine it as a macro. For example, this program:
int main() {
int linux = 0;
return linux;
}
is perfectly valid, and a conforming compiler must accept it. Predefining linux causes the declaration to be a syntax error.
Some older compilers (including the compiler you were using, with the options you were giving it) predefine certain symbols to provide information about the target platform -- including linux to indicate a Linux system. This convention goes back to early C compilers, written before there was a distinction between reserved and unreserved identifiers.
The identifier __linux__, since it starts with two underscores, is reserved for use by the implementation, so compilers are allowed to predefine it -- and compilers for Linux systems typically do predefine it as a macro expanding to 1.
Confirm that your compiler predefines __linux__, and then change your code so it tests __linux__ rather than linux. You should also find out what reserved symbol is used instead of i386 (likely __i386__).
Related: Why does the C preprocessor interpret the word "linux" as the constant "1"?
Change your standard-selection flag to -std=gnu++0x instead of c++0x. The gnu flavors provide some non-standard extensions, apparently including predefining the macro linux. Alternatively, check for __linux__ instead.
So, I built boost with the following script conveniently posted by toma
and it compiles and I can add the respective frameworks in Xcode6 to my iOS target and my OSX target.
It runs properly on iOS, but when I try compiling on OSX I get errors in has_binary_operator.hpp in the following lines:
template < typename Lhs, typename Rhs >
struct operator_exists {
static ::boost::type_traits::yes_type check(has_operator); // this version is preferred when operator exists
static ::boost::type_traits::no_type check(no_operator); // this version is used otherwise
BOOST_STATIC_CONSTANT(bool, value = (sizeof(check(((make<Lhs>() BOOST_TT_TRAIT_OP make<Rhs>()),make<has_operator>())))==sizeof(::boost::type_traits::yes_type)));
};
Error messages:
.../boost.framework/Headers/type_traits/detail/has_binary_operator.hpp:155:42: Expected member name or ';' after declaration specifiers
.../boost.framework/Headers/type_traits/detail/has_binary_operator.hpp:156:41: Expected member name or ';' after declaration specifiers
Screenshot:
PS: My stdlib is libc++ and I want to use C++11 and Clang in both iOS and MacOSX. I mean it works perfectly for iOS, so why is it not working with the MacOSX target?!?
Quickfix:
Undefining 'check' seems to solve the error, as this seems to be a keyword reserved on MacOSX. Still it seems a weird solution to just undefine an OSX keyword, wouldn't this cause problems later?
#undef check
#include <boost/multi_array.hpp>
check is not a keyword, but an unfortunately named macro in a file supplied by Apple.
This has been an ongoing problem for boost (and other library vendors) for many years.
The header file <AssertMacros.h> is where this macros is defined.
See https://svn.boost.org/trac/boost/ticket/2115 for some history on this.
The latest version of this file (that Apple ships with the 10.9 SDK) contains the following text:
Prior to Mac OS X 10.6 the macro names used in this file conflicted with some
user code, including libraries in boost and the proposed C++ standards efforts,
and there was no way for a client of this header to resolve this conflict. Because
of this, most of the macros have been changed so that they are prefixed with
__ and contain at least one capital letter, which should alleviate the current
and future conflicts. However, to allow current sources to continue to compile,
compatibility macros are defined at the end with the old names. A tops script
at the end of this file will convert all of the old macro names used in a directory
to the new names. Clients are recommended to migrate over to these new macros as
they update their sources because a future release of Mac OS X will remove the
old macro definitions ( without the double-underscore prefix ). Clients who
want to compile without the old macro definitions can define the macro
__ASSERT_MACROS_DEFINE_VERSIONS_WITHOUT_UNDERSCORES to 0 before this file is
included.
So, you could add -D__ASSERT_MACROS_DEFINE_VERSIONS_WITHOUT_UNDERSCORES=0 to your build commands to fix this problem.
Alternately, you could get a newer version of boost, where those calls have been renamed from check to s_check.
In Photoshop CS2 SDK file SPConfig.h, the follow code get error.Obviously I needed the define of __MWERKS__. The Compiler is LLVM GCC 4.2, the SDK is OS X 10.7 .
#ifdef __MWERKS__
#if !defined(__INTEL__) /* mjf was- #if defined(__MC68K__) || defined(__POWERPC__) */
#ifndef MAC_ENV
#define MAC_ENV 1
#endif
#endif
#endif
#if !defined(WIN_ENV) && !defined(MAC_ENV)
#error
#endif
In file cdefs.h:
#if defined(__MWERKS__) && (__MWERKS__ > 0x2400)
I want to know how to find where it defines. Or can I just define a number to it?
Those macros are defined by the compiler itself to indicate which compiler it is (so you can write compiler-specific things).
__MWERKS__ was used by Metrowerks CodeWarrior, which was discontinued in 2005, so is slightly obsolete by now.
You should not define it yourself - unless you're compiling with CodeWarrior, those parts should be skipped, or the program will most likely break in unpredictable ways.
Your actual problem is that your compiler & SDK combination isn't recognized as a Macintosh environment.
There must be some other place that defines MAC_ENV.
(I find it hard to believe that the CS2 SDK wouldn't support Apple's own compiler.)
You should go search for all occurrences of MAC_ENV.
Are you sure that the combination of SDKs and compiler you're using is supported?
The CS2 SDK is so old it might not be, so you should also read the documentation carefully.