News:

Simutrans.com Portal
Our Simutrans site. You can find everything about Simutrans from here.

[RC 11.9001] Compiling with clang on OS X 10.8

Started by MCollett, March 24, 2013, 01:19:06 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

MCollett

A recent upgrade from OS X 10.6 to 10.8  has resulted in me switching from gcc to clang as my working C++ compiler.  clang is noticeably fussier, and I have needed to make some changes to compile Simutrans successfully.

Required to compile:
1. In simtypes.h (adding alloca support for clang):
@@ -20,6 +20,9 @@
# define ALLOCA(type, name, count) type* name = static_cast<type*>(alloca(sizeof(type) * (count)))
#
# define inline _inline
+#elif defined __clang__
+# include <alloca.h>
+# define ALLOCA(type, name, count) type* name = static_cast<type*>(alloca(sizeof(type) * (count)))
#else
# define ALLOCA(type, name, count) type name[count]
#endif

2. In tpl/koordhashtable_tpl.h (the cast is unnecessary, unhelpful and illegal):
@@ -28,7 +28,7 @@

static void dump(const key_t key)
     {
- printf("%d, %d", (koord)key.x, (koord)key.y);
+ printf("%d, %d", key.x, key.y);
     }

static int comp(key_t key1, key_t key2)

3. In dataobj/einstellungen.h (the compiler needs to know that 'append' is a dependent name):
@@ -38,7 +38,7 @@
vector_with_ptr_ownership_tpl( vector_with_ptr_ownership_tpl const& src ) :
vector_tpl<T*>( src.get_count() ) {
ITERATE( src, i ) {
- append( new T( *src[i] ) );
+ this->append( new T( *src[i] ) );
}
}


With the above changes (and suppressing many more warnings than I like), the code compiles.  However, the game crashes with a segfault whenever I attempt to open a depot window.   Some detective work turned up the apparent culprit in gui/components/gui_button.h:
@@ -104,10 +104,8 @@
* direct acces provided to avoid translations
* @author Hj. Malthaner
*/
- union {
- const char * text;
- struct { sint16 x,y; } targetpos;
- };
+ struct { sint16 x,y; } targetpos;
+ const char * text;
const char *translated_text;

// private function for displaying buttons or their replacement

Evidently the union is somewhere written to through 'targetpos' and then read back through 'text', resulting in a illegal pointer value; removing the union stops the crashes.

The game now _appears_ to run OK.  makeobj on the other hand compiles and runs without complaint, but the resulting paks always have zero capacity for all stops ...

Best wishes,
Matthew

jamespetts

Thank you very much - that is most helpful. Firstly, as to the issues with the station sizes, that was not a Makeobj problem, but an issue in the code of the main program, which I have now fixed on my Github branch.

As to the Clang issues, I have incorporated the changes that you suggest. These look as though they might be issues applicable to Standard, too, however.
Download Simutrans-Extended.

Want to help with development? See here for things to do for coding, and here for information on how to make graphics/objects.

Follow Simutrans-Extended on Facebook.