Building couchbase-lite-core on Windows

Hi,

I’m trying to build couchbase-lite-core on Windows. I’m following the README instructions.

What I did:

cd build_cmake
cmake -G "Visual Studio 14 2015 Win64"
msbuild  LiteCore.sln /p:Configuration=RelWithDebInfo /t:LiteCore

It compiles for a long time but it ends in error:

Build FAILED.
"C:\Users\nsantos\workspace\couchbase_qt\couchbase-lite-core\build_cmake\LiteCore.sln" (LiteCore target) (1) ->
"C:\Users\nsantos\workspace\couchbase_qt\couchbase-lite-core\build_cmake\LiteCore.vcxproj.metaproj" (default target) (2) ->
"C:\Users\nsantos\workspace\couchbase_qt\couchbase-lite-core\build_cmake\LiteCoreStatic.vcxproj.metaproj" (default target) (10) ->
"C:\Users\nsantos\workspace\couchbase_qt\couchbase-lite-core\build_cmake\LiteCoreStatic.vcxproj" (default target) (11) -> (ClCompile target) -> C:\Users\nsantos\workspace\couchbase_qt\couchbase-lite-core\LiteCore\Query\QueryParser.cc(285): warning C4267: '+=': conversion from 'size_t' to 'unsigned int', possible loss of data [C:\Users\nsantos\workspace\couchbase_qt\couchbase-lite-core\build_cmake\LiteCoreStatic.vcxproj]
"C:\Users\nsantos\workspace\couchbase_qt\couchbase-lite-core\build_cmake\LiteCore.sln" (LiteCore target) (1) ->
"C:\Users\nsantos\workspace\couchbase_qt\couchbase-lite-core\build_cmake\LiteCore.vcxproj.metaproj" (default target) (2) -> "C:\Users\nsantos\workspace\couchbase_qt\couchbase-lite-core\build_cmake\LiteCoreStatic.vcxproj.metaproj" (default target) (10) ->
"C:\Users\nsantos\workspace\couchbase_qt\couchbase-lite-core\build_cmake\LiteCoreStatic.vcxproj" (default target) (11) -> (ClCompile target) -> C:\Users\nsantos\workspace\couchbase_qt\couchbase-lite-core\C\c4Base.cc(29): fatal error C1083: Cannot open include file: 'repo_version.h': No such file or directory [C:\Users\nsantos\workspace\couchbase_qt\couchbase-lite-core\build_cmake\LiteCoreStatic.vcxproj]

1 Warning(s)
1 Error(s)

Time Elapsed 00:00:06.29

In summary, it seems that the fact it can’t find repo_version.h is a problem:

Cannot open include file: 'repo_version.h'

It seems that repo_version.h is dynamicly generated. By who?

Can I workaround this issue manually?

Thanks in advance!

Regards,

Nuno

repo_version.h is generated during the CMake build.

CMake runs the powershell script $ROOT/build_cmake/scripts/get_repo_version.ps1 to create it.

Your cmake call is missing the final argument (the location of the CMakeList.txt file) which could also be affecting things.

@borrrden the missing was a typo of mine.

In the mean time I have found a couple of things…

I was executing the cmake in a normal command prompt. I have tried in a powershell but there was a similar result. The script get_repo_version.ps1 couldn’t be executed due to security restrictions. I had to call:

 Set-ExecutionPolicy -ExecutionPolicy Unrestricted -Scope
CurrentUser

In order to be able to call that script. Then I have tried to run the msbuild in the same powershell but no joy.

I have opened the regular command prompt and it has build successfully.

I think you should add this step to the README file. Cmake should be run on a powershell after setting an unrestricted execution policy.

Now I’m stumbling with linking errors, hundreds of them:

LiteCoreStatic.lib(c4Base.obj) : error LNK2038: mismatch detected for '_ITERATOR_DEBUG_LEVEL': value '0' doesn't match value '2' in main.obj
LiteCoreStatic.lib(c4Base.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MD_DynamicRelease' doesn't match value 'MTd_StaticDebug' in main.obj
LiteCoreStatic.lib(c4Database.obj) : error LNK2038: mismatch detected for '_ITERATOR_DEBUG_LEVEL': value '0' doesn't match value '2' in main.obj
LiteCoreStatic.lib(c4Database.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MD_DynamicRelease' doesn't match value 'MTd_StaticDebug' in main.obj
LiteCoreStatic.lib(c4Document.obj) : error LNK2038: mismatch detected for '_ITERATOR_DEBUG_LEVEL': value '0' doesn't match value '2' in main.obj
LiteCoreStatic.lib(c4Document.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MD_DynamicRelease' doesn't match value 'MTd_StaticDebug' in main.obj
LiteCoreStatic.lib(c4DocEnumerator.obj) : error LNK2038: mismatch detected for '_ITERATOR_DEBUG_LEVEL': value '0' doesn't match value '2' in main.obj
LiteCoreStatic.lib(c4DocEnumerator.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MD_DynamicRelease' doesn't match value 'MTd_StaticDebug' in main.obj
LiteCoreStatic.lib(c4Observer.obj) : error LNK2038: mismatch detected for '_ITERATOR_DEBUG_LEVEL': value '0' doesn't match value '2' in main.obj
...

I’m googling around to find a solution. If you have any suggestion, I’m all hears!

Thanks!

You need to compile all of your components with the same c++ runtime library variant. This kind of thing happens when you mix default debug and release builds for example since one will link with the debug runtime and the other with the release runtime.

@borrrden I have changed all the targets to link Runtime Library /MT and it is now working with my build kit.

Great success! :wink:

@sinosoidal can you help me to compile my one i am unable to do so…please check my post couchbase-lite-C unable to build library on windows - #2 by borrrden

@mostain this are my notes to build on Windows. Haven’t been through them for almost a year. Can’t promise it will work:

Building for Windows (Static)

Open Powershell and set execution policy to unrestricted on the current user. Then generate Visual Studio solution with cmake.

> Set-ExecutionPolicy -ExecutionPolicy Unrestricted -Scope CurrentUser
> cd couchbase-lite-core
> mkdir build_windows
> cd build_windows
> cmake.exe -G "Visual Studio 14 2015 Win64" ..

Open LiteCore solution and change all the targets Runtime Library setting to /MT and build solution

Hope it helps.

Regards,

Nuno

@sinosoidal thank you for you quick response…

i am able to generate visual studio solution file but when i open CouchbaseLite_C.sln file with visual studio 2019 i am getting following error:

13>Done building project “CouchbaseLiteC.vcxproj” – FAILED.
14>------ Build started: Project: CBL_C_Tests, Configuration: Release x64 ------
14>Building Custom Rule C:/Users/mostain/Desktop/couchbase/database/couchbase-lite-C/test/CMakeLists.txt
14>BlobTest_Cpp.cc
14>C:\Users\mostain\Desktop\couchbase\database\couchbase-lite-C\build_cmake\test..\include\cbl\cbl_config.h(19,10): fatal error C1083: Cannot open include file: ‘asprintf.h’: No such file or directory
14>CBLTestsMain.cpp
14>C:\Users\mostain\Desktop\couchbase\database\couchbase-lite-C\build_cmake\test..\include\cbl\cbl_config.h(19,10): fatal error C1083: Cannot open include file: ‘asprintf.h’: No such file or directory
14>DatabaseTest.cc
14>C:\Users\mostain\Desktop\couchbase\database\couchbase-lite-C\build_cmake\test..\include\cbl\cbl_config.h(19,10): fatal error C1083: Cannot open include file: ‘asprintf.h’: No such file or directory
14>DatabaseTest_Cpp.cc
14>C:\Users\mostain\Desktop\couchbase\database\couchbase-lite-C\build_cmake\test..\include\cbl\cbl_config.h(19,10): fatal error C1083: Cannot open include file: ‘asprintf.h’: No such file or directory
14>QueryTest.cc
14>C:\Users\mostain\Desktop\couchbase\database\couchbase-lite-C\build_cmake\test..\include\cbl\cbl_config.h(19,10): fatal error C1083: Cannot open include file: ‘asprintf.h’: No such file or directory
14>ReplicatorTest.cc
14>C:\Users\mostain\Desktop\couchbase\database\couchbase-lite-C\build_cmake\test..\include\cbl\cbl_config.h(19,10): fatal error C1083: Cannot open include file: ‘asprintf.h’: No such file or directory
14>Generating Code…
14>Done building project “CBL_C_Tests.vcxproj” – FAILED.
15>------ Build started: Project: ALL_BUILD, Configuration: Release x64 ------
========== Build: 11 succeeded, 4 failed, 0 up-to-date, 0 skipped ==========

can you guide me how i change all the targets Runtime Library setting to /MT and build solution ???

Please stop posting the same stuff in multiple places. You already opened a separate thread for this.