Page 1 of 1

Build issues on OSX

Posted: 14 Feb 2017 23:43
by tej
Hi,

I just cloned trunk from git.openttd.org
Attempted to build it, and was greeted by an error message at what seemed like the final linking step about the symbols iconv and open_iconv.

It seems that config.lib script doesn't detect the need to link with libiconv, so I made a patch for it:
https://gist.github.com/GBuella/ddcadef ... 3d1b510d39
( I didn't try this on other OS's )

Also, the configure script allows a build without even finding the iconv header -- iconv seems to be used in src/os/unix/unix.cpp
Probably this should be fixed as well.

About the patch:
The reason it didn't detect the need for -liconv, is that it didn't even find the header file in the first place. I removed the code looking for the header file with a test that just compiles a file #include-ing iconv.h -- clang installed with xcode knows about the correct sysroot, and finds iconv.h

On system:
MacOS Sierra 10.12.2, with newest Xcode installed, iconv.h happens to be at /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/iconv.h

I also tried to register an account in the bugtracker, but I didn't recieve a validation email yet...

Cheers,
Tej

Re: Build issues on OSX

Posted: 15 Feb 2017 17:39
by Snail
I also have a similar problem on Sierra: viewtopic.php?f=33&t=75390

Re: Build issues on OSX

Posted: 16 Feb 2017 11:47
by tej
Snail wrote:I also have a similar problem on Sierra: viewtopic.php?f=33&t=75390
Hi, I looked at that thread, and the patches.
It seems to me, that current trunk already has those patches, and more.
You might be trying to build on older version.
If you didn't yet, pull the current code, and try to build that. Compilation worked for me with no warnings at all, with a single argument given to configure (nolzma, or nolzo2, I don't remember which one).
I only ran into problem with linking, so I had to make it detect the need for -liconv.

Re: Build issues on OSX

Posted: 16 Feb 2017 22:37
by andythenorth
tej wrote:Compilation worked for me with no warnings at all, with a single argument given to configure (nolzma, or nolzo2, I don't remember which one).
Do you have anything installed from Macports or Brew? I need to upgrade to Sierra, and I am curious what deps might be needed to get OpenTTD to build. ;)

Re: Build issues on OSX

Posted: 18 Feb 2017 18:52
by Snail
Thanks, Tej! It looks like your patch did the trick :D I could compile and run OTTD on my OS X Sierra (10.12.3).

So I downloaded you patch and applied it with the following command:

Code: Select all

patch -p0 < config.lib.patch
after copying your "config.lib.patch" in the directory I put the "trunk" files in.
It looks like "config.lib" was successfully patched, however I got this output:

Code: Select all

patching file config.lib
patch unexpectedly ends in middle of line
Hunk #5 succeeded at 2942 with fuzz 1.
Then I ran "./configure", which still gave me the usual "clang" error message:

Code: Select all

clang: error: unsupported option '-dumpspecs'
clang: error: no input files
clang: error: unsupported option '-dumpspecs'
clang: error: no input files
I then launched the "make" command, and this time it seemed to be successful! Linking went on without errors, however I got a huge number of warnings (attached).
OpenTTD started correctly, and it looks like games work OK (including sound and music). The only thing I had to do, was to move to the latest version of "libpng" (i.e. version 16 : I had to install a new version of grfcodec, because my previous one only worked with libpng14).

Thank you very much for your patch. I guess it could be put in trunk, to help other people compile on Sierra.

Re: Build issues on OSX

Posted: 19 Feb 2017 02:14
by tej
The "patch unexpectedly ends in middle of line" might indicate, that the newest trunk has already changed after I made this patch.
BTW, my configure command is:

Code: Select all

CC=clang CXX=clang++ ./configure --without-liblzo2
Without specifying the CC and CXX variables, the commands cc and c++ should be used, but...
I'm used to configure scripts originating from GNU being horrible. They usually just try to use gcc instead of cc, cuz why not...
I have some older gcc installed (I think I built it from source sometime ago, and doesn't know the right sysroot), and without specifying CC and CXX, this gcc is used.
I can see the configure script detecting:

Code: Select all

checking build cc... gcc
checking host cc... gcc
checking build c++... gcc
checking host c++... gcc
This is absolutely ridiculos, the host cc is obviously clang, not gcc:

Code: Select all

$ cc -v
Apple LLVM version 8.0.0 (clang-800.0.42.1)
Target: x86_64-apple-darwin16.3.0
So is the host c++:

Code: Select all

$ c++ -v
Apple LLVM version 8.0.0 (clang-800.0.42.1)
Target: x86_64-apple-darwin16.3.0
So perhaps something goes wrong in your case as well, some gcc install with which doesn't work well, or it is trying to feed gcc arguments to clang ( I recall by default the gcc command is just an alias to clang, cuz apple also likes messing up things sometimes...)

When I specify CC and CXX:

Code: Select all

$ CC=clang CXX=clang++ ./configure --without-liblzo2
...
checking build cc... clang
checking host cc... clang
checking build c++... clang++
checking host c++... clang++
...

Re: Build issues on OSX

Posted: 19 Feb 2017 02:26
by Snail
tej wrote:BTW, my configure command is:

Code: Select all

CC=clang CXX=clang++ ./configure --without-liblzo2
You mean I should enter this line in the Terminal? When I do, I get this error message:

Code: Select all

CC=clang: Command not found.
Perhaps I'm using a wrong syntax?
tej wrote: I can see the configure script detecting:

Code: Select all

checking build cc... gcc
checking host cc... gcc
checking build c++... gcc
checking host c++... gcc
When I configured, I got the following:

Code: Select all

checking build cc... gcc
checking host cc... gcc
checking build c++... g++
checking host c++... g++
tej wrote: When I specify CC and CXX:

Code: Select all

$ CC=clang CXX=clang++ ./configure --without-liblzo2
...
checking build cc... clang
checking host cc... clang
checking build c++... clang++
checking host c++... clang++
...
I wonder why this syntax doesn't work for me.

Re: Build issues on OSX

Posted: 19 Feb 2017 02:27
by tej
I found some clues in the config.lib file, that might explain why you see those warnings and I don't see them:

Code: Select all

if [ `basename $1 | cut -c 1-3` = "icc" ]; then
	# Enable some things only for certain ICC versions
	....
elif [ `basename $1 | grep 'clang'` ]; then
	# Enable some things only for certain clang versions
	flags="$flags -Wall -W -Wextra"

	# warning: unused parameter '...'
	flags="$flags -Wno-unused-parameter"

	# warning: expression result unused
	flags="$flags -Wno-unused-value"

	# warning: multi-character character constant
	flags="$flags -Wno-multichar"
	
	# more warning stuff,etc....
else
        # Enable some things only for certain GCC versions
        flags="$flags -Wall -Wno-multichar -Wsign-compare -Wundef"
	flags="$flags -Wwrite-strings -Wpointer-arith"
	flags="$flags -W -Wno-unused-parameter -Wredundant-decls"
	flags="$flags -Wformat=2 -Wformat-security"
The above code snippet suggest, the misdetection of the compiler can result in different warnings issued.
On your machine is the gcc command an alias to clang, or do you also have a gcc installed from somewhere?
The output of this should probably contain either the string LLVM, or the string GCC:

Code: Select all

$ gcc -v

Re: Build issues on OSX

Posted: 19 Feb 2017 02:41
by tej
I wonder why this syntax doesn't work for me.
Strange, you might want to try it this way:

Code: Select all

./configure --without-liblzo2  CC=clang CXX=clang++

Re: Build issues on OSX

Posted: 19 Feb 2017 18:33
by Snail
tej wrote:The above code snippet suggest, the misdetection of the compiler can result in different warnings issued.
On your machine is the gcc command an alias to clang, or do you also have a gcc installed from somewhere?
The output of this should probably contain either the string LLVM, or the string GCC:

Code: Select all

$ gcc -v
This is what I'm getting:

Code: Select all

Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/usr/include/c++/4.2.1
Apple LLVM version 8.0.0 (clang-800.0.42.1)
Target: x86_64-apple-darwin16.4.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
tej wrote:
I wonder why this syntax doesn't work for me.
Strange, you might want to try it this way:

Code: Select all

./configure --without-liblzo2  CC=clang CXX=clang++
This works: now configuration gets done without that "clang" error.
When I compile, I'm still getting some warnings, but fewer than before. Attached. (The game seems to work fine)

Re: Build issues on OSX

Posted: 19 Feb 2017 21:22
by andythenorth
Would one of you update the wiki page about compiling on OS X? :) https://wiki.openttd.org/Compiling_on_M ... osemite.29

I kept it updated for Yosemite and Mavericks, but I don't have Sierra yet, and I don't like to put advice there that I haven't tested for myself. ;)

The OS X port isn't officially maintained, so the strategy is approximately:
1. some of the core devs try to keep the OS X port working without much/any access to OS X machines
2. hope kind strangers provide valid patches
3. keep the wiki up to date with advice about ./configure parameters are needed, and any advice on deps (the wiki is a central location, rather than digging through multiple threads or flyspray tickets)

:)