Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: [1] 2 3

Author Topic: On DFHack/plugins compilation with Xcode 7  (Read 4327 times)

mifki

  • Bay Watcher
  • works secretly...
    • View Profile
    • mifki
On DFHack/plugins compilation with Xcode 7
« on: November 18, 2015, 10:03:20 pm »

In Xcode 7 Apple has switched from GCC assembler to LLVM assembler. Even when using GCC to compile, it uses the system assembler. This (or maybe something else changed as well) led to problems compiling DFHack and plugins. When compiling with GCC 4.5, some of the resulting binaries crash, including the protobuf compiler that's build during DFHack build process. When compiling with later GCC versions, the new assembler can't compile one of the produced by GCC files.

Fortunately, you can have several Xcode versions installed, so you can install Xcode 6 to /Applications/Xcode_6.app (don't use path with spaces, as cmake will fail), and switch to it when needed with

Code: [Select]
sudo xcode-select -s /Applications/Xcode_6.app
Also the following symlink is required due to some library changes:

Code: [Select]
cd /usr/local/lib
sudo ln -s ../../lib/libSystem.B.dylib libgcc_s.10.5.dylib

And this is required because the old GCC doesn't know about newer systems (I've tried 10.5 but cmake failed, I think supporting 10.6 is enough nowadays):

Code: [Select]
export MACOSX_DEPLOYMENT_TARGET=10.6
With this, I was able to build working DFHack and my plugins on 10.11 with GCC 4.5 and Xcode 7 installed (besides Xcode 6). As I understand, xcode-select affects only console tools, so you can continue to run and use Xcode 7 for other development.

lethosor

  • Bay Watcher
    • View Profile
Re: On DFHack/plugins compilation with Xcode 7
« Reply #1 on: November 18, 2015, 11:00:30 pm »

Oh, did you get GCC 4.5 to compile on 10.11? I thought you said the 10.10 patch wasn't working.
Logged
DFHack - Dwarf Manipulator (Lua) - DF Wiki talk

There was a typo in the siegers' campfire code. When the fires went out, so did the game.

mifki

  • Bay Watcher
  • works secretly...
    • View Profile
    • mifki
Re: On DFHack/plugins compilation with Xcode 7
« Reply #2 on: November 18, 2015, 11:29:05 pm »

Oh, did you get GCC 4.5 to compile on 10.11? I thought you said the 10.10 patch wasn't working.

Did you read my post?:) It is about how to get GCC 4.5 working, and also it says that it's not a problem with new OS X version, but with new Xcode version, and also I don't know what 10.10 patch is. Updated the post to make it clear about GCC 4.5.

lethosor

  • Bay Watcher
    • View Profile
Re: On DFHack/plugins compilation with Xcode 7
« Reply #3 on: November 21, 2015, 01:14:14 pm »

I don't see anything about actually compiling GCC 4.5, though - how did you do that? (I thought there were issues in that step on 10.11.)
10.6 should be fine for a deployment target - it's what Toady uses, and Intel machines running 10.5 and below are pretty rare.
Logged
DFHack - Dwarf Manipulator (Lua) - DF Wiki talk

There was a typo in the siegers' campfire code. When the fires went out, so did the game.

mifki

  • Bay Watcher
  • works secretly...
    • View Profile
    • mifki
Re: On DFHack/plugins compilation with Xcode 7
« Reply #4 on: November 21, 2015, 03:05:16 pm »

Oh, you're talking about compiling GCC 4.5 itself... I'm pretty sure I've tried to reinstall it via homebrew first when I had this problem and it installs fine, so why do you want to compile it manually?

lethosor

  • Bay Watcher
    • View Profile
Re: On DFHack/plugins compilation with Xcode 7
« Reply #5 on: November 21, 2015, 03:23:48 pm »

Homebrew should be compiling it on 10.11. I'm surprised that it works, because Macports trac (where the patch is hosted) has been down for a while.
Logged
DFHack - Dwarf Manipulator (Lua) - DF Wiki talk

There was a typo in the siegers' campfire code. When the fires went out, so did the game.

mifki

  • Bay Watcher
  • works secretly...
    • View Profile
    • mifki
Re: On DFHack/plugins compilation with Xcode 7
« Reply #6 on: November 21, 2015, 03:42:50 pm »

I remember an error message about downloading a patch, but it doesn't seem to affect version 4.5 because homebrew is installing it from a binary "bottle". see the following messages

lethosor

  • Bay Watcher
    • View Profile
Re: On DFHack/plugins compilation with Xcode 7
« Reply #7 on: November 21, 2015, 04:12:30 pm »

On 10.11? From here, it looks like that should only work on 10.8-10.10, but maybe Homebrew is using 10.10 bottles on 10.11.
Would it be possible to point GCC to a GNU assembler somehow?
Logged
DFHack - Dwarf Manipulator (Lua) - DF Wiki talk

There was a typo in the siegers' campfire code. When the fires went out, so did the game.

mifki

  • Bay Watcher
  • works secretly...
    • View Profile
    • mifki
Re: On DFHack/plugins compilation with Xcode 7
« Reply #8 on: November 21, 2015, 04:34:47 pm »

On 10.11? From here, it looks like that should only work on 10.8-10.10, but maybe Homebrew is using 10.10 bottles on 10.11.
Would it be possible to point GCC to a GNU assembler somehow?

Oh yes, sorry, I keep forgetting I still have 10.10 on this machine, and it indeed fails on 10.11 because of the patch. However, since my 4.5 still works after upgrading to 10.11 on another machine, I wonder if it's possible to force homebrew to install Yosemite bottle on 10.11. I'll try on Monday.

I've read somewhere that GNU assembler can't produce binaries in the right format, so actually the only way to get the working GNU assembler is from Xcode < 7.

mifki

  • Bay Watcher
  • works secretly...
    • View Profile
    • mifki
Re: On DFHack/plugins compilation with Xcode 7
« Reply #9 on: November 23, 2015, 09:16:21 pm »

The server with GCC patches seems to be up again, I've managed to compile GCC 4.5 on 10.11 without problems. Here is a bottle in case the patch server will be down again: http://dffd.bay12games.com/file.php?id=11294

lethosor

  • Bay Watcher
    • View Profile
Re: On DFHack/plugins compilation with Xcode 7
« Reply #10 on: November 23, 2015, 09:50:07 pm »

It worked for you? TheBloke was running into this on 10.11: https://github.com/Homebrew/homebrew-versions/issues/1038

I have an alternative formula here - the only difference currently is that it stores patches in the repo, although I'm hoping to maintain support for GCC 4.5 if the Homebrew maintainers drop it.
Logged
DFHack - Dwarf Manipulator (Lua) - DF Wiki talk

There was a typo in the siegers' campfire code. When the fires went out, so did the game.

TheBloke

  • Bay Watcher
    • View Profile
Re: On DFHack/plugins compilation with Xcode 7
« Reply #11 on: November 23, 2015, 09:56:22 pm »

The server with GCC patches seems to be up again, I've managed to compile GCC 4.5 on 10.11 without problems. Here is a bottle in case the patch server will be down again: http://dffd.bay12games.com/file.php?id=11294

Cool that you got it working mifki - won't build at all for me, as lethosor mentioned.

What XCode do you have?  That may well be the difference.  I am on XCode 7.1.1.

Edit: sorry, I actually read the OP now!  I see you are side installing XCode 6, and I expect this is why you can build 4.5 and I can't.

Re the assembler errors, see below for how to build DFHack with XCode 7 (patch required to gcc 4.x):

Gcc 4.x  won't build DFHack if you have XCode 7+, it will fail on clang-assembler errors.   See here my pull request for homebrew/versions GCC 4.9 which fixes this, via a patch written for 5.x but still working on 4.9 at least.  I can't check yet if it works for 4.5 as well until I can build 4.5.  This patch is already applied to brew's gcc 5.2, so that will build OK - though not then actually work because of the name mangling issues.

Having applied that patch to brew install gcc49, I can now build DFHack fully with 4.9 - though I then need to replace libstdc++ manually afterwards.
« Last Edit: November 23, 2015, 10:08:20 pm by TheBloke »
Logged

mifki

  • Bay Watcher
  • works secretly...
    • View Profile
    • mifki
Re: On DFHack/plugins compilation with Xcode 7
« Reply #12 on: November 23, 2015, 10:07:01 pm »

Yep, it fails to build with Xcode 7. But builds fine if you install Xcode 6 and switch to it using xcode-select.

The issue with GCC 4.5 + Xcode 7 is different from GCC 4.9 + Xcode 7, and that patch will NOT help, see my original post. So you'll have to have Xcode 6 installed anyway to build DFHack with GCC 4.5, and it will let you build GCC 4.5 itself as well.

TheBloke

  • Bay Watcher
    • View Profile
Re: On DFHack/plugins compilation with Xcode 7
« Reply #13 on: November 23, 2015, 10:33:00 pm »

Yep, it fails to build with Xcode 7. But builds fine if you install Xcode 6 and switch to it using xcode-select.

The issue with GCC 4.5 + Xcode 7 is different from GCC 4.9 + Xcode 7, and that patch will NOT help, see my original post. So you'll have to have Xcode 6 installed anyway to build DFHack with GCC 4.5, and it will let you build GCC 4.5 itself as well.

OK I see.

In my view this would be a good time to move up to GCC 4.9 for OSX.  I was discussing that with lethosor earlier.  Once the assembler patch is applied, gcc 4.9 produces a fully working DFHack with either XCode 6 or XCode 7, and that patch should hopefully be on homebrew/versions soon.

That would avoid the need to also install XCode 6, and thus simplify instructions in Compile.rst etc.  Just one command - "brew install gcc49"  - instead of installing XCode 6 and the other necessary commands.

lethosor was concerned about testing for 10.6 compatibility with a gcc 4.9 compiled libstdcc+ so I'm getting a 10.6 host up so that can be checked.

So I think it could be quite straightforward, at least once 10.6 compatibility is confirmed?
Logged

mifki

  • Bay Watcher
  • works secretly...
    • View Profile
    • mifki
Re: On DFHack/plugins compilation with Xcode 7
« Reply #14 on: November 23, 2015, 10:49:51 pm »

I've seen various issues, including some weird crashes, because of compiler and/or libstdc++ incompatibility, so I'm personally quite happy with the Xcode 6 solution. Also, I'm worried about possibly more complicated installation instructions (like remove/replace libstdc++) for DFHack for users who want to add it manually to an existing DF installation.
Pages: [1] 2 3