openttd doesn't compile on OSX

Forum for technical discussions regarding development. If you have a general suggestion, problem or comment, please use one of the other forums.

Moderator: OpenTTD Developers

flyx
Engineer
Engineer
Posts: 8
Joined: 01 Apr 2010 12:11

Re: openttd doesn't compile on OSX

Post by flyx »

I just posted this because aantono asked for it. I didn't want to publish it as public patch or whatever here. I can remove it if you feel it should not be here.
aantono
Traffic Manager
Traffic Manager
Posts: 211
Joined: 15 Apr 2010 21:01
Location: Midwest, US

Re: openttd doesn't compile on OSX

Post by aantono »

flyx wrote:I just posted this because aantono asked for it. I didn't want to publish it as public patch or whatever here. I can remove it if you feel it should not be here.
Thanks a lot for the link. Will download it right now, before it disappears again. :)
aantono
Traffic Manager
Traffic Manager
Posts: 211
Joined: 15 Apr 2010 21:01
Location: Midwest, US

Re: openttd doesn't compile on OSX

Post by aantono »

Decided to compile my own distro but keep on getting error on the last steps of 'make' :(

Code: Select all

[SRC] Linking openttd
Undefined symbols:
  "_libiconv_open", referenced from:
      FS2OTTD(char const*)in unix.o
      OTTD2FS(char const*)in unix.o
  "_libiconv", referenced from:
      convert_tofrom_fs(void*, char const*)in unix.o
      convert_tofrom_fs(void*, char const*)in unix.o
ld: symbol(s) not found
collect2: ld returned 1 exit status
make[1]: *** [openttd] Error 1
make: *** [all] Error 2
Checked to see if the iconv lib is installed, and it seems to be.

Code: Select all

iconv --version
iconv (GNU libiconv 1.11)
Copyright (C) 2000-2007 Free Software Foundation, Inc.
License GPLv2+: GNU GPL version 2 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Written by Bruno Haible.
Can someone shed some light onto what I might be doing wrong?
Rubidium
OpenTTD Developer
OpenTTD Developer
Posts: 3815
Joined: 09 Feb 2006 19:15

Re: openttd doesn't compile on OSX

Post by Rubidium »

Most likely you have two iconvs and the iconv OpenTTD is compiled against (via the headers) is not the same as the one OpenTTD is linked to (via the library).
aantono
Traffic Manager
Traffic Manager
Posts: 211
Joined: 15 Apr 2010 21:01
Location: Midwest, US

Re: openttd doesn't compile on OSX

Post by aantono »

Rubidium wrote:Most likely you have two iconvs and the iconv OpenTTD is compiled against (via the headers) is not the same as the one OpenTTD is linked to (via the library).
Is there a way to tell ./configure to use a specific one, give it a path?
aantono
Traffic Manager
Traffic Manager
Posts: 211
Joined: 15 Apr 2010 21:01
Location: Midwest, US

Re: openttd doesn't compile on OSX

Post by aantono »

Found a solution:

My system is a SNOW LEOPARD 10.6.1

All these problems are generated because the Makefile is confused by the existence of multiple iconv library installations.

Fixing iconv (please note that these are pretty subjective, but they are a good start)

Needed elements:

1) gettext - http://ftp.gnu.org/pub/gnu/gettext/gettext-0.17.tar.gz
2) iconv - http://ftp.gnu.org/pub/gnu/libiconv/lib ... 3.1.tar.gz

Unpack both libraries, before running configure, prepare your environment as follows:

(i assume you have latest xcode)

export MACOSX_DEPLOYMENT_TARGET=10.6; export CFLAGS="-arch i386 -arch x86_64 -g -Os -pipe -no-cpp-precomp"; export CCFLAGS="-arch i386 -arch x86_64 -g -Os -pipe"; export CXXFLAGS="-arch i386 -arch x86_64 -g -Os -pipe" LDFLAGS="-arch i386 -arch x86_64 -bind_at_load"

and then run configure in gettext, leave prefix as it is, make & make install;

NOW, building iconv will replace existing iconv from apple(it shouldn't break anything)

./configure --prefix=/usr --enable-shared --enable-static

then:

make
sudo make install
aantono
Traffic Manager
Traffic Manager
Posts: 211
Joined: 15 Apr 2010 21:01
Location: Midwest, US

Re: openttd doesn't compile on OSX

Post by aantono »

flyx, can you let me know what environment settings have you used when you compiled your build of OpenTTD?
I'm getting some weird behavior with iconv library where I can't run both your and mine builds against the same libiconv.

I'm getting 'Symbol not found: _iconv_open' error if I run your build against my latest rebuild of iconv.
If I roll back the libiconv to what was on the machine before, your build runs fine, but I can't compile the game from trunk. (see earlier post about the error).
User avatar
planetmaker
OpenTTD Developer
OpenTTD Developer
Posts: 9432
Joined: 07 Nov 2007 22:44
Location: Sol d

Re: openttd doesn't compile on OSX

Post by planetmaker »

For me works:

Code: Select all

> #system libiconv:
> ls /usr/lib/libiconv.
libiconv.2.4.0.dylib  libiconv.2.dylib      libiconv.dylib  
> #macports libiconv:
> port installed libiconv
The following ports are currently installed:
  libiconv @1.13_0
  libiconv @1.13.1_0
  libiconv @1.13.1_0+universal (active)
> ls /opt/local/lib/libiconv.
libiconv.2.dylib  libiconv.a        libiconv.dylib    libiconv.la      
OSX 10.6.3 on Macbook.

EDIT: attached output of my configure. I use
CFLAGS='-isystem/opt/local/include '
but that might not be needed anymore.
Attachments
configure.txt
my configure output
(3.18 KiB) Downloaded 76 times
flyx
Engineer
Engineer
Posts: 8
Joined: 01 Apr 2010 12:11

Re: openttd doesn't compile on OSX

Post by flyx »

aantono, I didn't do anything to libiconv, I just linked against the one that came with MacOSX.

My build is linked against:

Code: Select all

$ otool -L openttd
openttd:
	...
	/usr/lib/libz.1.dylib (compatibility version 1.0.0, current version 1.2.3)
	/usr/lib/libiconv.2.dylib (compatibility version 7.0.0, current version 7.0.0)
	/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 125.0.1)
	/usr/lib/libobjc.A.dylib (compatibility version 1.0.0, current version 227.0.0)
	...
I did compile gettext 0.17 myself. If a replacement of libiconv breaks OpenTTD, I suggest you roll back to Apple's version and simply remove your second installation or make it unaccessible when compiling OpenTTD. I don't think it's a good idea to manually update stuff in /usr/lib. If your problem is that you have two libiconv libraries, replacing the one in /usr/lib just reduces the consequences, but doesn't solve the problem.
aantono
Traffic Manager
Traffic Manager
Posts: 211
Joined: 15 Apr 2010 21:01
Location: Midwest, US

Re: openttd doesn't compile on OSX

Post by aantono »

This is what my lib. dep looks like:

Code: Select all

bundle/OpenTTD.app/Contents/MacOS/openttd:
	/System/Library/Frameworks/Cocoa.framework/Versions/A/Cocoa (compatibility version 1.0.0, current version 15.0.0)
	/usr/lib/libstdc++.6.dylib (compatibility version 7.0.0, current version 7.9.0)
	/System/Library/Frameworks/Carbon.framework/Versions/A/Carbon (compatibility version 2.0.0, current version 152.0.0)
	/System/Library/Frameworks/AudioUnit.framework/Versions/A/AudioUnit (compatibility version 1.0.0, current version 1.0.0)
	/System/Library/Frameworks/AudioToolbox.framework/Versions/A/AudioToolbox (compatibility version 1.0.0, current version 1.0.0)
	/usr/lib/libz.1.dylib (compatibility version 1.0.0, current version 1.2.3)
	/usr/local/lib/libpng12.0.dylib (compatibility version 40.0.0, current version 40.0.0)
	/usr/local/lib/libfreetype.6.dylib (compatibility version 10.0.0, current version 10.20.0)
	/usr/local/lib/libiconv.2.dylib (compatibility version 7.0.0, current version 7.0.0)
	/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 124.1.1)
	/usr/lib/libobjc.A.dylib (compatibility version 1.0.0, current version 227.0.0)
	/System/Library/Frameworks/CoreServices.framework/Versions/A/CoreServices (compatibility version 1.0.0, current version 44.0.0)
	/System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation (compatibility version 150.0.0, current version 550.0.0)
	/System/Library/Frameworks/ApplicationServices.framework/Versions/A/ApplicationServices (compatibility version 1.0.0, current version 38.0.0)
	/System/Library/Frameworks/Foundation.framework/Versions/C/Foundation (compatibility version 300.0.0, current version 751.0.0)
	/System/Library/Frameworks/AppKit.framework/Versions/C/AppKit (compatibility version 45.0.0, current version 1038.11.0)
As it turns out, having Apple's libiconv and MacPorts libiconv does not work very well. I had to deactivate MacPorts one, and rebuild and repackage the src in order to get both working. Apparently something in MacPort's build is not compatible with the Apple's native one. To make things even trickier, if I download the latest libiconv src and build one myself, it is still not matching.

Here are the outputs of the exported functions:
For the Apple's one nm libiconv.2.dylib | grep iconv:

Code: Select all

000f4fa0 S ___iconv_2VersionNumber
00016114 S ___iconv_2VersionString
000f5be0 D __libiconv_version
0000859c T _iconv
00014d2d T _iconv_canonicalize
0000b905 T _iconv_close
00015049 T _iconv_open
000089fe T _iconvctl
0000860c T _iconvlist
00008603 T _libiconv
0000fcce T _libiconv_close
00015860 T _libiconv_open
00015d72 T _libiconv_relocate
00015d63 T _libiconv_set_relocation_prefix
00008b2d T _libiconvctl
0000879b T _libiconvlist
For the MacPort's one nm libiconv.2.dylib | grep iconv:

Code: Select all

000da904 D __libiconv_version
0001069f T _iconv_canonicalize
00006c53 T _libiconv
00009bd9 T _libiconv_close
00010995 T _libiconv_open
000116a1 t _libiconv_relocate
00011692 T _libiconv_set_relocation_prefix
0000701a T _libiconvctl
00006cba T _libiconvlist
For the hand-built one nm libiconv.2.dylib | grep iconv:

Code: Select all

000da904 D __libiconv_version
00010693 T _iconv_canonicalize
00006c47 T _libiconv
00009bcd T _libiconv_close
00010989 T _libiconv_open
00011695 t _libiconv_relocate
00011686 T _libiconv_set_relocation_prefix
0000700e T _libiconvctl
00006cae T _libiconvlist
... which appears to match what MacPorts is having, and looks like its missing the iconv* instructions, which is the cause of the problem.
Not to sure why that's the case, and how come the src downloaded from Apple's repository does not rebuild the matching lib as the one installed on the machine, but that's the case...

So it looks like removing the MacPorts libiconv library and restoring the one in /usr/lib to the original version, both builds work and mine compiles and links just fine.
aantono
Traffic Manager
Traffic Manager
Posts: 211
Joined: 15 Apr 2010 21:01
Location: Midwest, US

Re: openttd doesn't compile on OSX

Post by aantono »

Ah, the marvelous world of linking!!! Just when I thought I was done with it, turns out that I've linked against the wrong library yet again. Unbeknown to me, I had a THIRD variation of libiconv.2.dylib in /usr/local/lib and the build got linked against that.

So I've removed that one, as well as the corresponding iconv.h in /usr/local/include, then went ahead and recompiled the libfreetype.6.dylib just in case (it was working just fine, if I did ./configure --without-freetype before), and whuala!!! After all that hand movement, the build compiled, linked and started just fine!!!

Huge thanks to everyone who tried to help with suggestions, it was very helpful and pointed me in the right paths for digging! :)

If anyone wants the diff of the iconv.h files, let me know, got it all saved.
Post Reply

Return to “OpenTTD Development”

Who is online

Users browsing this forum: No registered users and 10 guests