Xcode 4: How to add custom GCC compiler arguments? - xcode

I'm building a C++ project, how do I add a custom compiler argument that Xcode doesn't have? Like -fwide-exec-charset=UCS-2LE. I searched on the internet but only found the solution to xcode 3.x. I'm using Xcode 4.5.2 and the UI is too different.
PS. It's NOT the commandline argument which used when debugging program, it's the g++ compiler argument which used when compiling the source codes.

Related

macOS Sierra CoreFoundation error while compiling wxWidgets for SimSpark

I am trying to to compile wxWidgets 3.0.2 found here.
I need this library, so that I can compile SimSpark.
I have tried installing the library via MacPorts - this does work. But when I try to compile SimSpark, the compiler states the following:
In file included from /opt/local/include/gcc49/c++/type_traits:35:0,
from /opt/local/Library/Frameworks/wxWidgets.framework/Versions/wxWidgets/3.0/include/wx-3.0/wx/strvararg.h:25,
from /opt/local/Library/Frameworks/wxWidgets.framework/Versions/wxWidgets/3.0/include/wx-3.0/wx/string.h:46,
from /opt/local/Library/Frameworks/wxWidgets.framework/Versions/wxWidgets/3.0/include/wx-3.0/wx/memory.h:15,
from /opt/local/Library/Frameworks/wxWidgets.framework/Versions/wxWidgets/3.0/include/wx-3.0/wx/object.h:19,
from /opt/local/Library/Frameworks/wxWidgets.framework/Versions/wxWidgets/3.0/include/wx-3.0/wx/event.h:16,
from /Users/YEED/Downloads/simspark-0.2.4/plugin/inputwx/inputwx.cpp:23:
/opt/local/include/gcc49/c++/bits/c++0x_warning.h:32:2: error: #error This file requires compiler and library support for the ISO C++ 2011 standard. This support is currently experimental, and must be enabled with the -std=c++11 or -std=gnu++11 compiler options.
I believe that I need to compile wxWidgets with C++11 support, since I already included the C++11 relevant flags when making SimSpark.
When I try to compile wxWidgets, I get a bunch of compiler errors that refer to the same .h file - which is part of CoreFoundation:
In file included from /usr/include/Availability.h:184:0,
from /usr/include/stdlib.h:61,
from /usr/include/assert.h:44,
from ../include/wx/debug.h:13,
from ../include/wx/defs.h:743,
from ../include/wx/wxprec.h:12,
from ../src/common/filefn.cpp:20:
/System/Library/Frameworks/CoreFoundation.framework/Headers/CFDateFormatter.h:53:34: error: expected '}' before '__attribute__'
kCFISO8601DateFormatWithYear API_AVAILABLE(macosx(10.12), ios(10.0), watchos(3.0), tvos(10.0)) = (1UL << 0),
When you look into that specific file, there are a bunch of lines that miss a closing ) and resemble the one printed by the compiler as well. (There should be a closing ) before the comma at the end of the line, right?)
So my question is, is this an actual error in CoreFoundation? If so, how can I fix this or work around it? Or am I actually completely misunderstanding the compiler error thrown when compiling SimSpark in the first place?
EDIT:
I couldn't get wxWidgets to compile, but I have fixed my issues compiling SimSpark with the MacPorts version of wxWidgets. The problem lay within using different compilers (gcc and clang) for the two.

Integrate a prebuilt .a into my Xcode 5

I'm trying to integrate a prebuilt a static c library (a .a library )into my Xcode 5 project. But it failed and returned tons of Apple Mach-O linker errors. What I did is I added the Library Search Path to correct path and added the Other C flags, Other C++ flags as something like -lmylib ( the lib file name is libmylib.a). I remembered it worked in my previous Xcode which using GCC.
Can anybody advise what I should do to fix the problem. Thanks.
Edit:
By adding these flags to Linker flag solved the problem. But I have another issue. The .a built for normal simulator doesn't work for the one with 64 bit. How should I solve this problem?
My bad. Add the flag to the wrong place. Should add to Other Linker Flag.

Xcode: setting to enable C++ even when no C++ sources are in the project?

I have an Objective-C/Cocoa project that incorporates a static library. That static library has some object files that have C++ in them.
I've found that if the project that I'm using the library in contains no other C++ in it, the link fails (can't link new/delete/etc). But simply adding a single (empty) .cpp file to the project causes the link to succeed.
In practice, what happens is that the build will invoke g++ instead of gcc when there is any cpp, which succeeds. No other difference in the build is apparent to me.
Is there an explicit switch I can use to link in this library without using the dummy cpp file in the project?
(This is mostly a curiosity question-- it's not the end of the world to put in one empty file. :) )
Thanks.
try to link libstdc++
gcc main.c -lstdc++
or in Xcode:
Project->Edit Project Settings
To the config section "Other Linker Flags", add -lstdc++.

How to static analyze C++ and Objective-C++ code?

The "Build and analyze" option doesn't seem to work for .cpp and .mm files. I tried "clang --analyze" on individual files without any standard #includes and it works well. However I'm not able to run it on my Xcode project. I couldn't figure out a way to make clang find the standard #includes like even UIKit.h. Any clues?
clang's C++ support is not complete yet clang web site
Apple's version is more explicit clang man page
Clang currently does not have C++ support
One way is to create symlinks to the Frameworks present in /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator3.1.2.sdk/System/Library/Frameworks/XXX.framework/Headers and point clang to the symlinks using the -I option.

Recompiled Qt libraries with VS, now why won't Qt Creator compile?

My initial goal was to get Qt Creator and Visual Studio 2008 to create compatible libraries, so what I've done so far was open a VS command prompt, go to my Qt folder and then run configure.exe followed by nmake to recompile the Qt libraries with VS. The problem is that now Qt creator won't compile anything. The compiler output shows that it is now using cl instead of gcc, which is what I wanted, but anytime I try to compile anything I get the following warnings:
:-1: warning: unrecognized option '/MANIFEST'; ignored
:-1: warning: unrecognized option '/MANIFESTFILE:debug\HelloQt.intermediate.manifest'; ignored
:-1: warning: unrecognized option '/MANIFESTDEPENDENCY:type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' publicKeyToken='6595b64144ccf1df' language='*' processorArchitecture='*''; ignored
I'm not sure if it makes a difference, but when I ran configure.exe I didn't set any command line parameters. I've noticed that references I've found have use different command line parameters when running configure.exe (although no two references use the same parameters), I'm not sure if running it from a VS command line was enough or if I was supposed to manually set some options.
This website uses a very long command line for configure.exe
configure -no-sql-sqlite -no-qt3support -no-opengl -platform win32-msvc2005 -no-libtiff -no-dbus -no-phonon -no-phonon-backend -no-webkit
although it appears he's disabling some options that I will need for my projects, and he didn't run it from a VS command prompt.
EDIT: recompiled with the -platform win32-msvc2008 parameter for configure.exe and it made no difference
My question is, what should I do about these "unrecognized options," and more generally is there anything else I need to do to get Qt creator to compile Qt projects with cl?
UPDATE
So I've tried recompiling the Qt libraries and upon actually reading the output from the 45+ minutes of compilation, I see that nmake is exiting with an error. I get eight "unresolved external symbol" errors from QNetworkReplyHandler.obj and FrameLoaderClientQt.obj before the compilation process is aborted. This doesn't seem like it would be causing the unrecognized option errors I've been receiving but it explains why the Qt libraries seem to run buggy when I'm using them with the Visual Studio Qt Plug-in. This problem is relatively unrelated so I've posted it in another question, here is the link just in case anyone has an answer for that problem.
The goal is to ensure you have a properly compiled QTDIR. In your case one for VS and one for gcc (if you want the two).
Depending on what you downloaded Qt Creator uses gcc but you can specify alternative QT directories under Options > Qt4 > Qt Versions. The path and version will show in the dialog box.
Go to the VS command line and run configure.exe & nmake with a clean source repository. Then add this QTDIR to you Qt Creator. I suggest you run make clean before.
Then make sure qmake and nmake can be run from the Qt command-line without errors. You should have a Qt Command line icon installed if you used Qt installer. If not, make sure you have QTDIR environment variable set, with %QTDIR%/bin in the path.
Do step 1 again, but this time do not use VS but make sure gcc is in the path. Run configure.exe etc again but in a separate directory specially for gcc. Add this version to your Qt Creator.
When compiling your project, run qmake first. You can change Qt versions, but do not forget to run qmake.
Hope this helps.
also, remember that QT Creator does not support debugging using CL
-- Lior

Resources