V4 currently doesnt build correctly on Windows

If you follow steps as below:

  1. unzip cocos2d-x-4.0.zip somewhere
  2. cd into cocos2d-x
  3. run setup.py. log in/log out to establish the env variables.
  4. execute cocos new blah -l cpp -p com.blah.blah
  5. cd blah\proj.win32
  6. cmake … -G “Visual Studio 16 2019” -AWin32
  7. open the solution in VS and build

The build fails with

2>------ Build started: Project: SYNC_RESOURCE-ae, Configuration: Debug Win32 ------
2>Copying resources for ae …
2> copying to C:/work/ae/proj.win32/bin/ae/Debug/Resources
2>‘PYTHON_COMMAND-NOTFOUND’ is not recognized as an internal or external command,
2>operable program or batch file.
2>C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\MSBuild\Microsoft\VC\v160\Microsoft.CppCommon.targets(155,5): error MSB3073: The command “setlocal
2>C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\MSBuild\Microsoft\VC\v160\Microsoft.CppCommon.targets(155,5): error MSB3073: “C:\Program Files\CMake\bin\cmake.exe” -E echo " copying to C:/work/ae/proj.win32/bin/ae/Debug/Resources”
2>C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\MSBuild\Microsoft\VC\v160\Microsoft.CppCommon.targets(155,5): error MSB3073: if %errorlevel% neq 0 goto :cmEnd
2>C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\MSBuild\Microsoft\VC\v160\Microsoft.CppCommon.targets(155,5): error MSB3073: PYTHON_COMMAND-NOTFOUND C:/work/ae/cocos2d/cmake/scripts/sync_folder.py -s C:/work/ae/Resources -d C:/work/ae/proj.win32/bin/ae/Debug/Resources
2>C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\MSBuild\Microsoft\VC\v160\Microsoft.CppCommon.targets(155,5): error MSB3073: if %errorlevel% neq 0 goto :cmEnd
2>C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\MSBuild\Microsoft\VC\v160\Microsoft.CppCommon.targets(155,5): error MSB3073: :cmEnd
2>C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\MSBuild\Microsoft\VC\v160\Microsoft.CppCommon.targets(155,5): error MSB3073: endlocal & call :cmErrorLevel %errorlevel% & goto :cmDone
2>C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\MSBuild\Microsoft\VC\v160\Microsoft.CppCommon.targets(155,5): error MSB3073: :cmErrorLevel
2>C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\MSBuild\Microsoft\VC\v160\Microsoft.CppCommon.targets(155,5): error MSB3073: exit /b %1
2>C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\MSBuild\Microsoft\VC\v160\Microsoft.CppCommon.targets(155,5): error MSB3073: :cmDone
2>C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\MSBuild\Microsoft\VC\v160\Microsoft.CppCommon.targets(155,5): error MSB3073: if %errorlevel% neq 0 goto :VCEnd
2>C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\MSBuild\Microsoft\VC\v160\Microsoft.CppCommon.targets(155,5): error MSB3073: :VCEnd" exited with code 9009.

you can get it to succeed by commenting out these two lines from SYNC_RESOURCE-blah/CMakeLists.txt:

cocos_get_resource_path(APP_RES_DIR ${APP_NAME})
cocos_copy_target_res(${APP_NAME} LINK_TO ${APP_RES_DIR} FOLDERS ${GAME_RES_FOLDER})

and just copying the resources yourself.

Also the above builds x86. Is there no canonical way to build to x64 right now?

You had everything right until you got to step 5.

Do not go into the proj.win32 folder, and don’t load any VS solution file that is in there, and don’t create the CMake project files in it either. You also shouldn’t need to modify anything in it unless you have a specific reason to do so.

From your root project folder, in your case named “blah”, do this:

mkdir build-win32
cd build-win32
cmake .. -G “Visual Studio 16 2019” -AWin32

Now open blah/build-win32/blah.sln.

Or, based on your error log, if you use the same “ae” project name, you should have this:

C:\work\ae\build-win32\ae.sln

You shouldn’t need to do any of that if you get the project creation via cmake correct.

2 Likes

@R101 I would guess that the v4 Windows setup doc is out of date at this point?

That doc is definitely out of date, and should be replaced with the instructions located here: https://github.com/cocos2d/cocos2d-x/tree/v4/cmake

Yeah , that document tells you to unzip the source code and then shows a screenshot of the contents that contains a build directory. If you uzip the currently available cocos2d-x-4.0.zip there is no build directory in it, so I immediately discounted that documentation as out of date.

I just tried it this way and get the same error. The location where cmake generates the solution is not the cause of the error I am seeing. Briefly the error is that the generated project "SYNC_RESOURCE-<project name>.vcxproj fails to build.

I think the problem is Visual Studio can’t run Python for some reason eveb though Python is in my path etc.-- I can open a cmd prompt and type in python and it’s there. ANyway I think that is what the error is.

If it is a Python issue, then run the Visual Studio installer, and check if it’s own version of Python is installed. If it isn’t, then install it, and see if that works:

image

Also, consider using the latest version from the github repo instead of the zip file version of Cocos2d-x v4, since it contains a lot of fixes for v4.

1 Like