Drexel
Drexel

Reputation: 11

Cocos2d-x Pre-built Not Working At All! Not Found Available Visual Studio

I am trying to do following ; http://www.cocos2d-x.org/docs/cocos2d-x/en/editors_and_tools/prebuilt_libraries.html

I got working copy of cocos2d-x 3.16. I compiled the cpp-test everything is working fine. I got VS2017.

But when i trying to create pre-built libraries this thing showed up. I could not find anything about it. Please help me guys!

OUTPUT :
C:\>cocos gen-libs -c win32
Not found VS2015
Not found VS2013
Not found available Visual Studio.
C:\>

IMAGE : not found available visual studio.

Upvotes: 0

Views: 623

Answers (1)

anuragyayhdapu
anuragyayhdapu

Reputation: 13

The problem is 'gen-libs' can't find MSBuild.exe

If you look in file utils.py

..\cocos2d-x-3.15.1\tools\cocos2d-console\bin\utils.py

In function get_msbuild_path(vs_version) :

def get_msbuild_path(vs_version):
# if cocos.os_is_win32():
#     import _winreg
# else:
#     return None

# if isinstance(vs_version, int):
#     # The value of vs_version is int. such as : 2013, 2015
#     if vs_version in VS_VERSION_MAP.keys():
#         vs_ver = VS_VERSION_MAP[vs_version]
#     else:
#         # not supported VS version
#         return None
# elif isinstance(vs_version, str):
#     # The value of vs_version is string. such as: "12.0", "14.0"
#     vs_ver = vs_version
# else:
#     return None

# # If the system is 64bit, find VS in both 32bit & 64bit registry
# # If the system is 32bit, only find VS in 32bit registry
# if cocos.os_is_32bit_windows():
#     reg_flag_list = [ _winreg.KEY_WOW64_32KEY ]
# else:
#     reg_flag_list = [ _winreg.KEY_WOW64_64KEY, _winreg.KEY_WOW64_32KEY ]

# # Find VS path
# msbuild_path = None
# for reg_flag in reg_flag_list:
#     try:
#         vs = _winreg.OpenKey(
#             _winreg.HKEY_LOCAL_MACHINE,
#             r"SOFTWARE\Microsoft\MSBuild\ToolsVersions\%s" % vs_ver,
#             0,
#             _winreg.KEY_READ | reg_flag
#         )
#         msbuild_path, type = _winreg.QueryValueEx(vs, 'MSBuildToolsPath')
#     except:
#         continue

#     if msbuild_path is not None:
#         msbuild_path = os.path.join(msbuild_path, "MSBuild.exe")
#         if os.path.exists(msbuild_path):
#             break
#         else:
#             msbuild_path = None

# return msbuild_path
return os.path.join("C:","\Program Files (x86)", "Microsoft Visual Studio", "2017", "Community", "MSBuild" , "15.0", "Bin", "MSBuild.exe")

As you can see it is trying to find a suitable version of visual studio Build Tool using Registry Keys 'HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\MSBuild\ToolsVersions' but registry entry isn't there.

What we can do instead is, comment this whole function and just return msbuild.exe path.

Notice the last line of above code snippet:

return os.path.join("C:","\Program Files (x86)", "Microsoft Visual Studio", "2017", "Community", "MSBuild" , "15.0", "Bin", "MSBuild.exe")

So, comment entire def get_msbuild_path(vs_version) function, and at the end add above return statement.

You might have to change above path if you have installed your visual studio in some other directory.


Next, open config file gen_libs_config.json

..\cocos2d-x-3.15.1\tools\cocos2d-console\plugins\plugin_generate\configs\gen_libs_config.json

and make sure at the end 'support_vs_versions' looks like this

"support_vs_versions" : [ 2015, 2013, 2017 ]

if it doesn't has 2017, then add it & save.


Lastly, go to directory

..\cocos2d-x-3.15.1\tools\simulator\frameworks\runtime-src\proj.win32\

and open solution simulator.sln in Visual studio. On startup it will prompt to retarget all projects from an older version of Visual C++ to a newer one. Press Yes, and wait for visual studio to complete its work. Once the editor becomes idle. Close the solution.


Finally, try to run gen-libs command, like so:

cocos2d gen-libs -p win32 --vs 2017 -m debug

Upvotes: 1

Related Questions