Compilers

How to print all defined macros of a compiler/arch

g++ -dM -E - < /dev/null

XCode 4

Linking with a dylib project

Set LD_DYLIB_INSTALL_NAME to @executable_path/$(EXECUTABLE_NAME) to make the dylib path-independent 1

Exporting and including Public Headers between two projects (i.e., one dylib, one command line)

  1. Library project - Select the header file to be made public, set its Target Membership (in the file inspector) to public
  2. Tool project - Add dylib project to Build Phases/Link Binary with Libraries list
  3. Tool project - Set ALWAYS_SEARCH_USER_PATHS to true
  4. Library project - For some idiotic reason, Xcode will search a directory $(LIBRARYOUTPUTDIR)/include, even though that's not any of the defaults for the header copy, so in Packaging, set PUBLIC_HEADERS_FOLDER_PATH to /include

Changing the idiotic default output path for builds

Preferences / Locations / Advanced / Custom - Relative to Workspace

Adding custom llvm/clang to Xcode:

http://stackoverflow.com/a/22260899/170511

Including headers inside the project

http://stackoverflow.com/questions/5413338/xcode-4-and-nested-projects-header-files-not-found

Forget the whole public header thing with Xcode, it's a PITA and doesn't work correctly when archiving your app. Instead, have all static library header files on the project level and tell your app where to find it.

  1. In build settings, point the Header Search Paths (if you use #include ) or User Header Search Paths (if you use #include "file.h") to the directory of the static library project. If the static library project is inside your app directory, use this:

    • "$(PROJECT_DIR)" (recursive enabled)
  2. If you have a directory which contains a) the static library project and b) your app, then this should work:

    • "$(PROJECT_DIR)/.." (recursive enabled)
  3. If the submodule contains compiled libraries, set your Library Search Paths to:

    • "$(TARGETBUILDDIR)"
  4. Make sure all the static library projects that you use have Skip Install set to YES.

  5. Again, no public header files (Build Phases ยป Copy Headers) in any of the static libraries, otherwise Xcode will not be able to archive an app.

  6. Make sure to tell Xcode when to build the static libraries, as shown in this Tech Doc from Apple

Getting Xcode to include LLVM /c++ headers

  1. Create script build phase before compile phase

    LLVM_XCCONFIG="llvm.xcconfig"
    OTHER_CPPFLAGS=`/usr/local/bin/lvm-config-3.4 --cppflags`
    OTHER_CFLAGS=`/usr/local/bin/lvm-config-3.4 --cflags`
    OTHER_CXXFLAGS=`/usr/local/bin/lvm-config-3.4 --cxxflags`
    OTHER_LDFLAGS=`/usr/local/bin/llvm-config-3.4 --ldflags" "/usr/local/bin/llvm-config-3.4 --libs cbackend jit x86 linker`
    echo "// Configuration file for LLVM settings, generated as a build phase." > $LLVM_XCCONFIG
    echo "OTHER_CPPFLAGS = $OTHER_CPPFLAGS" >> $LLVM_XCCONFIG
    echo "OTHER_CFLAGS = $OTHER_CFLAGS" >> $LLVM_XCCONFIG
    echo "OTHER_CXXFLAGS = $OTHER_CXXFLAGS" >> $LLVM_XCCONFIG
    echo "OTHER_LDFLAGS = $OTHER_LDFLAGS" >> $LLVM_XCCONFIG

  2. Build the project, xcconfig file gets generated, add it to project

  3. Set xcconfig as base configuration for all targets

    • Select Project, go to Info, add configuration on targets
  4. Add LLVM_LDFLAGS linker flags

changed April 15, 2014