The International Simutrans Forum

 

Author Topic: How to compile Simutrans Extended with Visual Studio 2015 [2019]  (Read 28475 times)

0 Members and 1 Guest are viewing this topic.

Offline ACarlotti

  • *
  • Posts: 483
Re: How to compile Simutrans Extended with Visual Studio 2015
« Reply #35 on: May 16, 2019, 12:01:28 AM »
That's an error in the code that wasn't previously spotted because most of us use multithreaded builds.

I was intending to make the thread await functions available in single threaded builds to allow a reduction the number of ifdefs needed elsewhere in the code, but failed to put the declarations outside the #ifdef MULTI_THREAD, and further failed to notice that the function definitions are inside a 600 line #ifdef MULTI_THREAD. There are two possible fixes to this - either put lines 4301 and 5581 inside #ifdefs, or put the function declarations and definitions outside ifdefs.

James: I've uploaded the latter solution to Github, but if you think the former fix would be better then we could probably do that instead.

Spenk009: You can wait for a fix upstream, but if you want to compile the code before then you can either switch to using a multithreaded build, or comment out the two lines that are causing errors.

EDIT: A thought on the merits of being able to call the await functions without #ifdefs - at the moments there is some inconstency about what condition is being tested - e.g. MULTI_THREAD_PATH_EXPLORER v.s. just MULTI_THREAD. If we can just call awaits whenever, then we don't need to worry about choosing between several valid conditions.

Offline Spenk009

  • Devotee
  • *
  • Posts: 354
  • Languages: en, de
Re: How to compile Simutrans Extended with Visual Studio 2015
« Reply #36 on: May 16, 2019, 07:25:14 AM »
Please excuse my ignorance, but what parameter do I add to make a multithreaded build?

Offline ACarlotti

  • *
  • Posts: 483
Re: How to compile Simutrans Extended with Visual Studio 2015
« Reply #37 on: May 16, 2019, 03:00:24 PM »
The intended way to configure a build is to copy config.template to config.default, and then uncomment/edit the relevant lines. The template config file has MULTI_THREAD=1 set, so you wouldn't need to change that further unless you wanted to comment it out or set it to 0 (for a build without multithreading). You can also set BACKEND, COLOUR_DEPTH and OSTYPE here , so that you don't need to specify them each time on the command line (and doing so will probably make it less likely that you accidentally specify the wrong parameters on the command line, which could get your build into an inconsistent state).

Offline jamespetts

  • Simutrans-Extended project coordinator
  • Administrator
  • *
  • Posts: 20774
  • Cake baker
    • Bridgewater-Brunel
  • Languages: EN
Re: How to compile Simutrans Extended with Visual Studio 2015
« Reply #38 on: May 18, 2019, 09:45:34 AM »
Splendid, thank you: fix incorporated.

Offline Ves

  • Devotee
  • *
  • Posts: 1820
  • Languages: EN, SV, DK
Re: How to compile Simutrans Extended with Visual Studio 2015
« Reply #39 on: January 16, 2021, 09:07:07 PM »
Returning to trying to compiling, I dont get this to work at all. It appears to not work "out of the box" anymore as described in the OP.

It seems that a new bunch of dependencies is required, which I have now found online and even compiled myself, and also I would like to know what debug and release compile modes should be used now ("Debug x64", "Debug (Open GL) x64"?).

Anyone with insight could perhaps shed some light on what exactly is required?

Offline jamespetts

  • Simutrans-Extended project coordinator
  • Administrator
  • *
  • Posts: 20774
  • Cake baker
    • Bridgewater-Brunel
  • Languages: EN
Re: How to compile Simutrans Extended with Visual Studio 2015
« Reply #40 on: January 16, 2021, 10:15:16 PM »
The only two compile modes that are still used are Debug and Optimised Debug, both in x64. Have you managed to get the dependencies working?

Offline Ves

  • Devotee
  • *
  • Posts: 1820
  • Languages: EN, SV, DK
Re: How to compile Simutrans Extended with Visual Studio 2015
« Reply #41 on: January 17, 2021, 07:17:05 PM »
Ok, thanks for the debug modes, that is a start.

No I havent got the dependencies to work properly, let me explain in detail what I have done:

Making a clean install of the entire Simutrans-extended Github repository, so as to reset all dependency path's etc.
Opening the Simutrans-extended.sln with MSVS2019, I immedietly check that it is set to "Debug" and "x64".
Opening the Include Directories I find that these are targeted:
Code: [Select]
..\zstd-1.4.4\lib
..\freetype-2.10.1\include\freetype
..\miniupnpc
..\OpenTTD\shared\include
..\bzip\include

and the Library Directories:
Code: [Select]
..\zstd-1.4.4\build\VS2010\bin\x64_Debug
..\freetype-2.10.1
..\miniupnpc
..\OpenTTD\win64\library
..\bzip\lib\x64
... which I assume are the correct paths to the corresponding files on your computer, James?
AND I assume this is a good representation on what dependencies I need.

zstd-1.4.4
I found the Zipfile named "zstd-1.4.4.zip" here: https://github.com/facebook/zstd/archive/v1.4.4.zip (direct download link)
Then, in order to get hold of the libzstd_static.lib (which the compiler will complain about), I followed the instructions on this webbsite https://rocksdb.org.cn/doc/Building-on-Windows.html ca 1/3rd down the page under the "Build Zstd" section (although I compiled the zstd.sln using msvs2019, right clicking on each project clicking "build" inside msvs2019)
Doing this creates a new folder structure bin\x64_Debug, which incidentally coincides with one of the Library Directories listed above.

Because I put all my dependency directories one level up from the Simutrans-extended.vcxproj file, the above paths should be equal to the ones already specifyed in the directories.

freetype-2.10.1
I found this directory online listing a bunch of freetype downloads: https://download.savannah.gnu.org/releases/freetype/
I picked the one called freetype-2.10.1.tar.gz (what is the difference between the ones ending with .gz and .xz??), downloaded and extracted it.
When comparing the folder structure with the directories listed above, one is pointing to freetype-2.10.1\include\freetype which appears ok, but the other is just pointing to the freetype-2.10.1 folder itself. The compiler will complain about not finding freetype.lib, so I went ahead and compiled that using the "freetype.sln" found in "freetype-2.10.1\builds\windows\vc2010". I set it to Release x64.
This ends up in "freetype.lib" being found in freetype-2.10.1\objs\x64\Release. I move it to the freetype-2.10.1 base folder, since that is the one pointed to by the Simutrans project.

miniupnpc
I found on this site a bunch of files relating to miniupnpc: http://miniupnp.free.fr/files/
Downloading the one called: miniupnpc-2.2.1.tar.gz, I get a folder with a bunch of header files and some folders. Looking at the project directories, they both points to the basefolder, without any version numbering as well. So I extract the folder, remove the "-2.2.1" from the folder name. The compiler (it should really be called a complainer....) will complain about not finding miniupnpc.lib, so I went ahead and compiled the miniupnpc.sln found in miniupnpc\msvc. To compile succesfully I had to rename "miniupnpcstrings.h.in" to just "miniupnpcstrings.h" (removing the .in) found in the base miniupnpc folder.
The resulting "miniupnpc.lib" ends up in "miniupnpc\msvc\Debug", which is not refered to by the project directories, so I just move it to the base miniupnpc folder.

OpenTTD
I remember this being a tricky one and I have several copies on my harddrive which might come in handy. Anyway, I downloaded a fresh one from this site: https://www.openttd.org/downloads/openttd-useful-releases/latest.html
Extracting this gives me a folder called "OpenTTD essentials", but I rename it to just "OpenTTD" in order to match the directories from the project. Other than that, the folder structure and files within seems to match the directories called to by the project.

bzip
I assume that this refers to bzip2, as all references points to that. Following the OP, it links to this site: https://github.com/philr/bzip2-windows/releases.
That download generates a folder with just a few files, not following the folder structure that the project include and library directories suggest.
Instead of following the OP suggestion (putting it within the Simutrans-Extended\utils\openttd\lib) I add the relevant intermedian folders and rename the parent folder to just bzip.


Compiling time:
It complains about pthread.h is missing. I have located a pthread.h in the utils\openttd folder within the simutrans-Extended folder, so I went ahead and added this directory to to the include- and library directories (include: utils\openttd - Library: utils\openttd\lib)

Now it just throws a big bunch of linker errors at me, lnk2001 and lnk2019 specifically:
Code: [Select]
Build started...
1>------ Build started: Project: Simutrans-Extended, Configuration: Debug x64 ------
1>git : Not a git repository warning GitNR1: Git output not valid! Check if the folder is actually versioned. A revision file already exists and its revision number won't be updated. Make sure the revision number is correct or you won't be able to play online with this build.
1>LINK : warning LNK4098: defaultlib 'MSVCRTD' conflicts with use of other libs; use /NODEFAULTLIB:library
1>LINK : warning LNK4217: symbol 'calloc' defined in 'libucrtd.lib(calloc.obj)' is imported by 'libzstd_static.lib(zstd_common.obj)' in function 'ZSTD_calloc'
1>LINK : warning LNK4286: symbol 'free' defined in 'libucrtd.lib(free.obj)' is imported by 'libzstd_static.lib(zstd_v06.obj)'
1>LINK : warning LNK4286: symbol 'free' defined in 'libucrtd.lib(free.obj)' is imported by 'libzstd_static.lib(zstd_v07.obj)'
1>LINK : warning LNK4286: symbol 'free' defined in 'libucrtd.lib(free.obj)' is imported by 'libzstd_static.lib(fse_decompress.obj)'
1>LINK : warning LNK4217: symbol 'free' defined in 'libucrtd.lib(free.obj)' is imported by 'libzstd_static.lib(zstd_common.obj)' in function 'ZSTD_free'
1>LINK : warning LNK4286: symbol 'free' defined in 'libucrtd.lib(free.obj)' is imported by 'libzstd_static.lib(fse_compress.obj)'
1>LINK : warning LNK4286: symbol 'free' defined in 'libucrtd.lib(free.obj)' is imported by 'libzstd_static.lib(xxhash.obj)'
1>LINK : warning LNK4217: symbol 'free' defined in 'libucrtd.lib(free.obj)' is imported by 'libzstd_static.lib(zstd_v05.obj)' in function 'MEM_swap64'
1>LINK : warning LNK4286: symbol 'malloc' defined in 'libucrtd.lib(malloc.obj)' is imported by 'libzstd_static.lib(zstd_v06.obj)'
1>LINK : warning LNK4286: symbol 'malloc' defined in 'libucrtd.lib(malloc.obj)' is imported by 'libzstd_static.lib(zstd_v07.obj)'
1>LINK : warning LNK4286: symbol 'malloc' defined in 'libucrtd.lib(malloc.obj)' is imported by 'libzstd_static.lib(fse_decompress.obj)'
1>LINK : warning LNK4217: symbol 'malloc' defined in 'libucrtd.lib(malloc.obj)' is imported by 'libzstd_static.lib(zstd_common.obj)' in function 'ZSTD_malloc'
1>LINK : warning LNK4217: symbol 'malloc' defined in 'libucrtd.lib(malloc.obj)' is imported by 'libzstd_static.lib(fse_compress.obj)' in function 'FSE_compress_wksp'
1>LINK : warning LNK4286: symbol 'malloc' defined in 'libucrtd.lib(malloc.obj)' is imported by 'libzstd_static.lib(xxhash.obj)'
1>LINK : warning LNK4217: symbol 'malloc' defined in 'libucrtd.lib(malloc.obj)' is imported by 'libzstd_static.lib(zstd_v05.obj)' in function 'MEM_readLEST'
1>LINK : warning LNK4217: symbol '_errno' defined in 'libucrtd.lib(errno.obj)' is imported by 'libzstd_static.lib(threading.obj)' in function 'ZSTD_pthread_create'
1>simview.obj : error LNK2019: unresolved external symbol __imp_pthread_attr_init referenced in function "public: void __cdecl main_view_t::display(bool)" (?display@main_view_t@@QEAAX_N@Z)
1>loadsave.obj : error LNK2001: unresolved external symbol __imp_pthread_attr_init
1>simworld.obj : error LNK2001: unresolved external symbol __imp_pthread_attr_init
1>simview.obj : error LNK2019: unresolved external symbol __imp_pthread_attr_destroy referenced in function "public: void __cdecl main_view_t::display(bool)" (?display@main_view_t@@QEAAX_N@Z)
1>loadsave.obj : error LNK2001: unresolved external symbol __imp_pthread_attr_destroy
1>simworld.obj : error LNK2001: unresolved external symbol __imp_pthread_attr_destroy
1>simview.obj : error LNK2019: unresolved external symbol __imp_pthread_attr_setdetachstate referenced in function "public: void __cdecl main_view_t::display(bool)" (?display@main_view_t@@QEAAX_N@Z)
1>loadsave.obj : error LNK2001: unresolved external symbol __imp_pthread_attr_setdetachstate
1>simworld.obj : error LNK2001: unresolved external symbol __imp_pthread_attr_setdetachstate
1>simview.obj : error LNK2019: unresolved external symbol __imp_pthread_create referenced in function "public: void __cdecl main_view_t::display(bool)" (?display@main_view_t@@QEAAX_N@Z)
1>loadsave.obj : error LNK2001: unresolved external symbol __imp_pthread_create
1>simworld.obj : error LNK2001: unresolved external symbol __imp_pthread_create
1>simworld.obj : error LNK2019: unresolved external symbol __imp_pthread_mutex_lock referenced in function "public: bool __cdecl karte_t::load(char const *)" (?load@karte_t@@QEAA_NPEBD@Z)
1>weg.obj : error LNK2001: unresolved external symbol __imp_pthread_mutex_lock
1>simgraph16.obj : error LNK2001: unresolved external symbol __imp_pthread_mutex_lock
1>simcity.obj : error LNK2001: unresolved external symbol __imp_pthread_mutex_lock
1>simconvoi.obj : error LNK2001: unresolved external symbol __imp_pthread_mutex_lock
1>simhalt.obj : error LNK2001: unresolved external symbol __imp_pthread_mutex_lock
1>simplay.obj : error LNK2001: unresolved external symbol __imp_pthread_mutex_lock
1>freelist.obj : error LNK2001: unresolved external symbol __imp_pthread_mutex_lock
1>loadsave.obj : error LNK2001: unresolved external symbol __imp_pthread_mutex_lock
1>powernet.obj : error LNK2001: unresolved external symbol __imp_pthread_mutex_lock
1>route.obj : error LNK2001: unresolved external symbol __imp_pthread_mutex_lock
1>label.obj : error LNK2001: unresolved external symbol __imp_pthread_mutex_lock
1>leitung2.obj : error LNK2001: unresolved external symbol __imp_pthread_mutex_lock
1>tunnel.obj : error LNK2001: unresolved external symbol __imp_pthread_mutex_lock
1>wayobj.obj : error LNK2001: unresolved external symbol __imp_pthread_mutex_lock
1>simview.obj : error LNK2001: unresolved external symbol __imp_pthread_mutex_lock
1>bruecke.obj : error LNK2001: unresolved external symbol __imp_pthread_mutex_lock
1>crossing.obj : error LNK2001: unresolved external symbol __imp_pthread_mutex_lock
1>gebaeude.obj : error LNK2001: unresolved external symbol __imp_pthread_mutex_lock
1>simworld.obj : error LNK2019: unresolved external symbol __imp_pthread_mutex_unlock referenced in function "public: bool __cdecl karte_t::load(char const *)" (?load@karte_t@@QEAA_NPEBD@Z)
1>weg.obj : error LNK2001: unresolved external symbol __imp_pthread_mutex_unlock
1>simgraph16.obj : error LNK2001: unresolved external symbol __imp_pthread_mutex_unlock
1>simcity.obj : error LNK2001: unresolved external symbol __imp_pthread_mutex_unlock
1>simconvoi.obj : error LNK2001: unresolved external symbol __imp_pthread_mutex_unlock
1>simhalt.obj : error LNK2001: unresolved external symbol __imp_pthread_mutex_unlock
1>simplay.obj : error LNK2001: unresolved external symbol __imp_pthread_mutex_unlock
1>freelist.obj : error LNK2001: unresolved external symbol __imp_pthread_mutex_unlock
1>loadsave.obj : error LNK2001: unresolved external symbol __imp_pthread_mutex_unlock
1>powernet.obj : error LNK2001: unresolved external symbol __imp_pthread_mutex_unlock
1>route.obj : error LNK2001: unresolved external symbol __imp_pthread_mutex_unlock
1>label.obj : error LNK2001: unresolved external symbol __imp_pthread_mutex_unlock
1>leitung2.obj : error LNK2001: unresolved external symbol __imp_pthread_mutex_unlock
1>tunnel.obj : error LNK2001: unresolved external symbol __imp_pthread_mutex_unlock
1>wayobj.obj : error LNK2001: unresolved external symbol __imp_pthread_mutex_unlock
1>simview.obj : error LNK2001: unresolved external symbol __imp_pthread_mutex_unlock
1>bruecke.obj : error LNK2001: unresolved external symbol __imp_pthread_mutex_unlock
1>crossing.obj : error LNK2001: unresolved external symbol __imp_pthread_mutex_unlock
1>gebaeude.obj : error LNK2001: unresolved external symbol __imp_pthread_mutex_unlock
1>simview.obj : error LNK2019: unresolved external symbol __imp_pthread_barrier_init referenced in function "public: void __cdecl main_view_t::display(bool)" (?display@main_view_t@@QEAAX_N@Z)
1>loadsave.obj : error LNK2001: unresolved external symbol __imp_pthread_barrier_init
1>simworld.obj : error LNK2001: unresolved external symbol __imp_pthread_barrier_init
1>simworld.obj : error LNK2019: unresolved external symbol __imp_pthread_barrier_wait referenced in function "public: bool __cdecl karte_t::load(char const *)" (?load@karte_t@@QEAA_NPEBD@Z)
1>simview.obj : error LNK2001: unresolved external symbol __imp_pthread_barrier_wait
1>loadsave.obj : error LNK2001: unresolved external symbol __imp_pthread_barrier_wait
1>route.obj : error LNK2001: unresolved external symbol __imp_pthread_barrier_wait
1>simconvoi.obj : error LNK2001: unresolved external symbol __imp_pthread_barrier_wait
1>simview.obj : error LNK2019: unresolved external symbol __imp_pthread_cond_wait referenced in function "public: void __cdecl main_view_t::display_region(class koord,class koord,short,short,bool,bool,signed char)" (?display_region@main_view_t@@QEAAXVkoord@@0FF_N1C@Z)
1>loadsave.obj : error LNK2001: unresolved external symbol __imp_pthread_cond_wait
1>simview.obj : error LNK2019: unresolved external symbol __imp_pthread_cond_broadcast referenced in function "public: void __cdecl main_view_t::display_region(class koord,class koord,short,short,bool,bool,signed char)" (?display_region@main_view_t@@QEAAXVkoord@@0FF_N1C@Z)
1>loadsave.obj : error LNK2001: unresolved external symbol __imp_pthread_cond_broadcast
1>network.obj : error LNK2019: unresolved external symbol freeUPNPDevlist referenced in function "bool __cdecl prepare_for_server(char *,char *,int)" (?prepare_for_server@@YA_NPEAD0H@Z)
1>network.obj : error LNK2019: unresolved external symbol upnpDiscover referenced in function "bool __cdecl prepare_for_server(char *,char *,int)" (?prepare_for_server@@YA_NPEAD0H@Z)
1>network.obj : error LNK2019: unresolved external symbol UPNP_GetValidIGD referenced in function "bool __cdecl prepare_for_server(char *,char *,int)" (?prepare_for_server@@YA_NPEAD0H@Z)
1>network.obj : error LNK2019: unresolved external symbol FreeUPNPUrls referenced in function "bool __cdecl prepare_for_server(char *,char *,int)" (?prepare_for_server@@YA_NPEAD0H@Z)
1>network.obj : error LNK2019: unresolved external symbol UPNP_GetExternalIPAddress referenced in function "bool __cdecl prepare_for_server(char *,char *,int)" (?prepare_for_server@@YA_NPEAD0H@Z)
1>network.obj : error LNK2019: unresolved external symbol UPNP_AddPortMapping referenced in function "bool __cdecl prepare_for_server(char *,char *,int)" (?prepare_for_server@@YA_NPEAD0H@Z)
1>network.obj : error LNK2019: unresolved external symbol UPNP_DeletePortMapping referenced in function "void __cdecl remove_port_forwarding(int)" (?remove_port_forwarding@@YAXH@Z)
1>loadsave.obj : error LNK2019: unresolved external symbol __imp_pthread_join referenced in function "public: void __cdecl loadsave_t::set_buffered(bool)" (?set_buffered@loadsave_t@@QEAAX_N@Z)
1>simworld.obj : error LNK2001: unresolved external symbol __imp_pthread_join
1>loadsave.obj : error LNK2019: unresolved external symbol __imp_pthread_mutex_init referenced in function "public: void __cdecl loadsave_t::set_buffered(bool)" (?set_buffered@loadsave_t@@QEAAX_N@Z)
1>simworld.obj : error LNK2001: unresolved external symbol __imp_pthread_mutex_init
1>simgraph16.obj : error LNK2001: unresolved external symbol __imp_pthread_mutex_init
1>loadsave.obj : error LNK2019: unresolved external symbol __imp_pthread_mutex_destroy referenced in function "public: void __cdecl loadsave_t::set_buffered(bool)" (?set_buffered@loadsave_t@@QEAAX_N@Z)
1>simworld.obj : error LNK2001: unresolved external symbol __imp_pthread_mutex_destroy
1>simgraph16.obj : error LNK2001: unresolved external symbol __imp_pthread_mutex_destroy
1>loadsave.obj : error LNK2019: unresolved external symbol __imp_pthread_barrier_destroy referenced in function "public: void __cdecl loadsave_t::set_buffered(bool)" (?set_buffered@loadsave_t@@QEAAX_N@Z)
1>simworld.obj : error LNK2001: unresolved external symbol __imp_pthread_barrier_destroy
1>simworld.obj : error LNK2019: unresolved external symbol __imp_pthread_exit referenced in function "void * __cdecl unreserve_route_threaded(void *)" (?unreserve_route_threaded@@YAPEAXPEAX@Z)
1>simworld.obj : error LNK2019: unresolved external symbol __imp_pthread_mutexattr_init referenced in function "public: void __cdecl karte_t::init_threads(void)" (?init_threads@karte_t@@QEAAXXZ)
1>weg.obj : error LNK2001: unresolved external symbol __imp_pthread_mutexattr_init
1>simworld.obj : error LNK2019: unresolved external symbol __imp_pthread_mutexattr_destroy referenced in function "public: void __cdecl karte_t::destroy_threads(void)" (?destroy_threads@karte_t@@QEAAXXZ)
1>simworld.obj : error LNK2019: unresolved external symbol __imp_pthread_mutexattr_settype referenced in function "public: void __cdecl karte_t::init_threads(void)" (?init_threads@karte_t@@QEAAXXZ)
1>simworld.obj : error LNK2019: unresolved external symbol __imp_sem_init referenced in function "private: void __cdecl karte_t::world_xy_loop(void (__cdecl karte_t::*)(short,short,short,short),unsigned char)" (?world_xy_loop@karte_t@@AEAAXP81@EAAXFFFF@ZE@Z)
1>simworld.obj : error LNK2019: unresolved external symbol __imp_sem_destroy referenced in function "private: void __cdecl karte_t::world_xy_loop(void (__cdecl karte_t::*)(short,short,short,short),unsigned char)" (?world_xy_loop@karte_t@@AEAAXP81@EAAXFFFF@ZE@Z)
1>simworld.obj : error LNK2019: unresolved external symbol __imp_sem_wait referenced in function "private: static void * __cdecl karte_t::world_xy_loop_thread(void *)" (?world_xy_loop_thread@karte_t@@CAPEAXPEAX@Z)
1>simworld.obj : error LNK2019: unresolved external symbol __imp_sem_post referenced in function "private: static void * __cdecl karte_t::world_xy_loop_thread(void *)" (?world_xy_loop_thread@karte_t@@CAPEAXPEAX@Z)
1>weg.obj : error LNK2019: unresolved external symbol __imp_pthread_rwlock_destroy referenced in function "public: virtual __cdecl weg_t::~weg_t(void)" (??1weg_t@@UEAA@XZ)
1>weg.obj : error LNK2019: unresolved external symbol __imp_pthread_rwlock_rdlock referenced in function "public: void __cdecl weg_t::delete_all_routes_from_here(bool)" (?delete_all_routes_from_here@weg_t@@QEAAX_N@Z)
1>weg.obj : error LNK2019: unresolved external symbol __imp_pthread_rwlock_wrlock referenced in function "public: void __cdecl weg_t::add_private_car_route(class koord,class koord3d)" (?add_private_car_route@weg_t@@QEAAXVkoord@@Vkoord3d@@@Z)
1>weg.obj : error LNK2019: unresolved external symbol __imp_pthread_rwlock_unlock referenced in function "public: void __cdecl weg_t::add_private_car_route(class koord,class koord3d)" (?add_private_car_route@weg_t@@QEAAXVkoord@@Vkoord3d@@@Z)
1>libzstd_static.lib(threading.obj) : error LNK2019: unresolved external symbol __imp__beginthreadex referenced in function ZSTD_pthread_create
1>utils\openttd\lib\pthreadVC2.lib : warning LNK4272: library machine type 'x86' conflicts with target machine type 'x64'
1>..\miniupnpc\miniupnpc.lib : warning LNK4272: library machine type 'x86' conflicts with target machine type 'x64'
1>.\simutrans\Simutrans-Extended-debug.exe : fatal error LNK1120: 34 unresolved externals
1>Done building project "Simutrans-Extended.vcxproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

I higly suspect that there are some aspects which I have missed, either in which files I have downloaded, or the ones I have compiled myself.
I would be very happy for assistance with this.

Offline jamespetts

  • Simutrans-Extended project coordinator
  • Administrator
  • *
  • Posts: 20774
  • Cake baker
    • Bridgewater-Brunel
  • Languages: EN
Re: How to compile Simutrans Extended with Visual Studio 2015
« Reply #42 on: January 20, 2021, 11:24:10 PM »
I had similar problems - I think that the __imp prefix means that you are trying to use static linking on a library compiled for dynamic linking. Many of the libraries you will have to compile yourself as 64-bit versions are not available. This is generally not too hard as they all have Visual Studio projects, but some care is needed in making sure that you have the properties set for a static build. There was one case where one of the libraries (I now forget which one) had lots of different sets of properties and I had changed the wrong one, which caused great difficulties for some time.

The libraries that you seem to be missing appear to be:

pthreads
miniupnpc

The others do not seem to be an issue. Have a look at how you have set up those libraries in particular. Note that you can compile Simutrans-Extended without miniupnpc if you do not define support for this (this is just for easier self-hosting of servers using the graphical client), but pthreads is essential.

Offline prissi

  • Developer
  • Administrator
  • *
  • Posts: 10636
  • Languages: De,EN,JP
Re: How to compile Simutrans Extended with Visual Studio 2015
« Reply #43 on: January 21, 2021, 01:33:40 PM »
The library needed is pthreadVC2.lib (or some other number, must match the pthread.h).

Offline Ves

  • Devotee
  • *
  • Posts: 1820
  • Languages: EN, SV, DK
Re: How to compile Simutrans Extended with Visual Studio 2015
« Reply #44 on: January 21, 2021, 10:04:54 PM »
Thank you, both.

I made it through the pthreadVC2.lib, and I found the one on this site with the matching version number: ftp://sourceware.org/pub/pthreads-win32/prebuilt-dll-2-9-1-release/lib/x64/

I have not been able to make miniupnpc work at all, it gave me 7 error of similar nature as before, but slightly different:
Code: [Select]
Build started...
1>------ Build started: Project: Simutrans-Extended, Configuration: Debug x64 ------
1>git : Not a git repository warning GitNR1: Git output not valid! Check if the folder is actually versioned. A revision file already exists and its revision number won't be updated. Make sure the revision number is correct or you won't be able to play online with this build.
1>libzstd_static.lib(zstd_common.obj) : MSIL .netmodule or module compiled with /GL found; restarting link with /LTCG; add /LTCG to the link command line to improve linker performance
1>LINK : warning LNK4075: ignoring '/INCREMENTAL' due to '/LTCG' specification
1>network.obj : error LNK2001: unresolved external symbol freeUPNPDevlist
1>network.obj : error LNK2001: unresolved external symbol upnpDiscover
1>network.obj : error LNK2001: unresolved external symbol UPNP_GetValidIGD
1>network.obj : error LNK2001: unresolved external symbol FreeUPNPUrls
1>network.obj : error LNK2001: unresolved external symbol UPNP_GetExternalIPAddress
1>network.obj : error LNK2001: unresolved external symbol UPNP_AddPortMapping
1>network.obj : error LNK2001: unresolved external symbol UPNP_DeletePortMapping
1>.\simutrans\Simutrans-Extended-debug.exe : fatal error LNK1120: 7 unresolved externals
1>Done building project "Simutrans-Extended.vcxproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
However, I managed to shutoff the miniupnpc, by editing the properties of the solution and remove the USE_UPNP from the Preprocessor Definitions. But strangely, it still required me to have the miniupnpc.lib located for it to continue compiling, which doesnt make sense to me...

The problem with the libzstd_static.lib resolved itself after I went over and made a release build, instead of a debug build. I got confused, because the directories from the Simutrans project file is looking at ..\zstd-1.4.4\build\VS2010\bin\x64_Debug, suggesting that it is supposed to be a debug build. Copying over from the x64_Release solved that.

Now it appears to compile,

Then I found the .dll files needed for it to run (on my windows 10) here:
freetype.dll: Found in the downloaded dependency (after compiling) in the path: freetype-2.10.1\objs
pthreadVC2.dll: Version 15.1.0.0 (the x64 version), found on this webbsite: https://www.dll-files.com/pthreadvc2.dll.html
libbz2.dll: Version 1.0.6 (the x64 version), found on this webbsite: https://github.com/philr/bzip2-windows/releases

Thank you for your help with this, it was quite exhaustive to navigate.....
Perhaps the OP can be updated as well? I would be happy to more organized describe step by step what I have done for this to compile.

Offline jamespetts

  • Simutrans-Extended project coordinator
  • Administrator
  • *
  • Posts: 20774
  • Cake baker
    • Bridgewater-Brunel
  • Languages: EN
Re: How to compile Simutrans Extended with Visual Studio 2015
« Reply #45 on: January 22, 2021, 09:35:01 AM »
Excellent, glad that you have got it working. If you were to suggest some edits to the OP, I should happily incorporate them.

Offline Ves

  • Devotee
  • *
  • Posts: 1820
  • Languages: EN, SV, DK
Re: How to compile Simutrans Extended with Visual Studio 2015
« Reply #46 on: January 22, 2021, 07:06:50 PM »
Ok, I will gladly do that. In the mean time, I cannot compile a release build.

I have set the exact same dependencies as with the debug build, and removed the USE_UPNP from the Preprocessor Definitions, and I get these errors:

Code: [Select]
Build started...
1>------ Build started: Project: Simutrans-Extended, Configuration: Release x64 ------
1>git : Not a git repository warning GitNR1: Git output not valid! Check if the folder is actually versioned. A revision file already exists and its revision number won't be updated. Make sure the revision number is correct or you won't be able to play online with this build.
1>Generating code
1>0 of 21410 functions ( 0.0%) were compiled, the rest were copied from previous compilation.
1>  0 functions were new in current compilation
1>  0 functions had inline decision re-evaluated but remain unchanged
1>Finished generating code
1>CVTRES : fatal error CVT1100: duplicate resource.  type:MANIFEST, name:1, language:0x0409
1>LINK : fatal error LNK1123: failure during conversion to COFF: file invalid or corrupt
1>Done building project "Simutrans-Extended.vcxproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

I realize there is a dublet somewhere of something, but what?

Offline jamespetts

  • Simutrans-Extended project coordinator
  • Administrator
  • *
  • Posts: 20774
  • Cake baker
    • Bridgewater-Brunel
  • Languages: EN
Re: How to compile Simutrans Extended with Visual Studio 2015
« Reply #47 on: January 22, 2021, 10:12:18 PM »
I no longer produce release builds in Visual Studio, only debug and optimised debug builds. Release builds are built on the Bridgewater-Brunel server. For this reason, the release build configuration is not set up to work. I suggest using the optimised debug build instead.

Offline Roboron

  • Devotee
  • *
  • Posts: 284
    • Las Galácticas Aventuras de Komoyo Diga
  • Languages: ES, EN
Compile issues
« Reply #48 on: January 22, 2021, 11:17:20 PM »
Trying to compile with UPNP support is failing to find the library. Seems that Extended import it using  "#include <miniupnpc.h>" while Standard import it with "#include <miniupnpc/miniupnpc.h>". Is this because the miniupnpc changes are not yet fully incorporated or for other reason?

Offline Ves

  • Devotee
  • *
  • Posts: 1820
  • Languages: EN, SV, DK
Re: How to compile Simutrans Extended with Visual Studio 2015
« Reply #49 on: January 23, 2021, 03:57:47 PM »
Oh, that explains alot!

So, what is the difference between them? What situations calls for the different build types?

Offline jamespetts

  • Simutrans-Extended project coordinator
  • Administrator
  • *
  • Posts: 20774
  • Cake baker
    • Bridgewater-Brunel
  • Languages: EN
Re: How to compile Simutrans Extended with Visual Studio 2015
« Reply #50 on: January 23, 2021, 07:26:17 PM »
Oh, that explains alot!

So, what is the difference between them? What situations calls for the different build types?

Optimised debug has most of the optimisations enabled. This means that it will run a great deal faster than a standard debug build. However, the optimisations make the debugger less effective: it is often not possible to view the value of variables in the debugger because they have been optimised away.

Use this build when you want to test performance (including using the performance profiler) or want to run a map that is so big that it is unusably unresponsive with a standard debug build.

The ordinary debug build is slower, but it does not enable optimisations, which means that debugging is more effective. Use this build when testing using the debugger except in the situations outlined above.

For actually playing, I suggest using the binary downloaded from the Bridgewater-Brunel server.

Offline Ves

  • Devotee
  • *
  • Posts: 1820
  • Languages: EN, SV, DK
Re: How to compile Simutrans Extended with Visual Studio 2015
« Reply #51 on: January 23, 2021, 10:26:28 PM »
Ok thanks, good to know.

One last thing:
Do I have to just stash in git the alterations I made to Simutrans-Extended.vcxproj in order to be able to do actual work?


---
Edit:

This is what I had to download and do to make Simutrans Extended compile with Microsoft Visual Studio 2019 on my 64 bit Windows 10 computer.

When Simutrans-Extended is downloaded fresh, the dependency directories will point to whatever directories the author of the Simutrans-Extended project made them point to. As the below list should be a complete set of dependencies, you can erase all existing entries from the include- and library directories.
I usually put my dependencies one folder up from where the Simutrans-Extended.sln is located. If you put your the same location, you can just copy/paste the entries from this post.
Please note that this guide is aimed towards a 64 bit compilation. I am unsure wether 32 bit is possible, but you would need to download and compile the 32 bit correspondence to all the below downloads instead.

Make sure that you are editing the project properties for both Debug x64 and Optimized debug x64, as those are the two compile modes currently available.



zstd-1.4.4
- Download v1.4.4.zip from here (direct download link): https://github.com/facebook/zstd/archive/v1.4.4.zip
- Unzip and put the folder zstd-1.4.4 in your dependency directory.
- Navigate to the file zstd.sln, located in zstd-1.4.4\build\VS2010 and open with MSVS 2019. Let it do any upgrades if it asks to.
- Set the configuration and platform to Release x64
- In the Solution Explorer rightclick on the project called libzstd and press build.
- This will create a file called libzstd_static.lib, which is what we need. Just leave it in place.

Simutrans-Extended project properties directories:
Include directory: ..\zstd-1.4.4\lib
Library directory: ..\zstd-1.4.4\build\VS2010\bin\x64_Release


freetype-2.10.1
- Download freetype-2.10.1.tar.gz from here: https://download.savannah.gnu.org/releases/freetype/
- Unzip and put the folder freetype-2.10.1 in your dependency directory.
- Navigate to the file freetype.sln, located in freetype-2.10.1\builds\windows\vc2010 and open it with MSVS 2019. Let it do any upgrades if it asks to.
- Set the configuration and platform to Release x64
- Build the solution.
- This will create a file called freetype.lib, which is what we need. Just leave it in place.
- Also it creates freetype.dll, but we will get back to this.

Simutrans-Extended project properties directories:
Include directory: ..\freetype-2.10.1\include\freetype
Library directory: ..\freetype-2.10.1\objs\x64\Release


OpenTTD essentials
- Download openttd-useful-6.0-win.zip from here (choose in the drop down box): https://www.openttd.org/downloads/openttd-useful-releases/latest.html
- Unzip and put the folder OpenTTD essentials in your dependency directory. Rename it to OpenTTD (otherwise it will not work).
- No more actions is needed with this dependency.

Simutrans-Extended project properties directories:
Include directory: ..\OpenTTD\shared\include
Library directory: ..\OpenTTD\win64\library


bzip2
- Download bzip2-dev-1.0.8.0-win-x64.zip from here: https://github.com/philr/bzip2-windows/releases
- Unzip and put the folder bzip2-dev-1.0.8.0-win-x64 in your dependency directory.
- No more actions is needed with this dependency.

Simutrans-Extended project properties directories:
Include directory: ..\bzip2-dev-1.0.8.0-win-x64
Library directory: ..\bzip2-dev-1.0.8.0-win-x64


miniupnpc
Disclaimer: I never made this dependency work on my computer, therefore this is a guide as to how to shut the feature requiring this dependency off. Unfortunately, the game still needs the files from this dependency to work, which is why we must download and install anyway.
- Download miniupnpc-2.2.1.tar.gz from here: http://miniupnp.free.fr/files/
- Unzip and put in the folder miniupnpc-2.2.1 in your dependency directory.
- Navigate to the file genminiupnpcstrings.vbs, located in miniupnpc-2.2.1\msvc and run it. Press "Open" on the security warning. This is a necessary first step!
- Then find the file miniupnpc.sln, also located in miniupnpc-2.2.1\msvc and open it with MSVS 2019. Let it do any upgrades if it asks to.
- Set the configuration and platform to Release Win32 (there is no x64 option)
- Build the solution (using the green "play" button).
- This will create a file called miniupnpc.lib, which is what we need. Just leave it in place.

Simutrans-Extended project properties directories:
Include directory: ..\miniupnpc-2.2.1
Library directory: ..\miniupnpc-2.2.1\msvc\Release

How to shut off miniupnpc:
- In the Simutrans-Extended project properties, navigate the menu to C/C++ -> Preprocessor.
- Click edit on the Preprocessor Definitions.
- Locate the phrase USE_UPNP in the list, and remove it entirely.


Pthreads
- Download pthreadVC2.lib from here: sourceware.org/pub/pthreads-win32/prebuilt-dll-2-9-1-release/lib/x64/
- Put the pthreadVC2.lib into this directory: Simutrans-extended\utils\openttd\lib
Note: If you have problems with pthread when compiling, make sure that the version you download matches the version in pthread.h (#define PTW32_VERSION) location: Simutrans-extended\utils\openttd

Simutrans-Extended project properties directories: (note that these directories is inside the Simutrans-extended project folder)
Include directory: utils\openttd
Library directory: utils\openttd\lib


Now, just to sum up:
Complete list of Include Directories:
Code: [Select]
..\zstd-1.4.4\lib
..\freetype-2.10.1\include\freetype
..\OpenTTD\shared\include
..\bzip2-dev-1.0.8.0-win-x64
..\miniupnpc-2.2.1
utils\openttd

Complete list of Library Directories:
Code: [Select]
..\zstd-1.4.4\build\VS2010\bin\x64_Release
..\freetype-2.10.1\objs\x64\Release
..\OpenTTD\win64\library
..\bzip2-dev-1.0.8.0-win-x64
..\miniupnpc-2.2.1\msvc\Release
utils\openttd\lib


Now compile the game using the Debug x64 or Optimized debug x64 configuration.
Only a few things left to do:

Download/locate these three .dll files:
- freetype.dll: Found in the downloaded dependency (after compiling) in the path: freetype-2.10.1\objs
- pthreadVC2.dll: Version 15.1.0.0 (the x64 version), found on this webbsite: https://www.dll-files.com/pthreadvc2.dll.html
- libbz2.dll: Version 1.0.6 (the x64 version), found on this webbsite: https://github.com/philr/bzip2-windows/releases
After you have downloaded/located all three, put them in this folder: Simutrans-extended\simutrans
Note that this folder might not exist until you run the compiler at least once.
« Last Edit: January 23, 2021, 10:47:39 PM by Ves »

Offline jamespetts

  • Simutrans-Extended project coordinator
  • Administrator
  • *
  • Posts: 20774
  • Cake baker
    • Bridgewater-Brunel
  • Languages: EN
Re: How to compile Simutrans Extended with Visual Studio 2015
« Reply #52 on: January 24, 2021, 11:38:57 AM »
Trying to compile with UPNP support is failing to find the library. Seems that Extended import it using  "#include <miniupnpc.h>" while Standard import it with "#include <miniupnpc/miniupnpc.h>". Is this because the miniupnpc changes are not yet fully incorporated or for other reason?

I have moved this post into a more appropriate topic, as this was not specifically about incorporating changes from Standard. Robron - I suggest that you read the above discussion and follow the steps that Ves used to get this working.

Edit:  Incidentally, Ves, that is very helpful - I have put a link to your post in the first post of this page and directed people to it. Thank you.

Offline Roboron

  • Devotee
  • *
  • Posts: 284
    • Las Galácticas Aventuras de Komoyo Diga
  • Languages: ES, EN
Re: How to compile Simutrans Extended with Visual Studio 2015 [2019]
« Reply #53 on: January 26, 2021, 06:22:18 PM »
I have moved this post into a more appropriate topic, as this was not specifically about incorporating changes from Standard. Robron - I suggest that you read the above discussion and follow the steps that Ves used to get this working.

I'm not using VSCode to compile Extended. But anyway, I don't really need help compiling Extended with miniupnpc support, I just can change the imports to match Standard's and that will work. I just wanted to know why it is not imported the same way as Standard does, since now I have to write a patch to compile Extended the same way I compile Standard. Sorry if I didn't post in the correct thread.

P.D.: But be cautious when moving messages, since I was not susbcribed to this thread and I got no notification email. I just discovered this because I look at the RSS from time to time.