AeroSun
AeroSun

Reputation: 2561

Python script: how to fix CMake Error: Could not create named generator?

When I use command line I can generate build with following line

cmake -B "D:\Builds" -S "D:\src" -G "Visual Studio 16 2019" -A "x64" 

When I use followed Pytnon script:

subprocess.call([
    '...\cmake.exe', 
    '-B "D:\Builds"',
    '-S "D:\src"',
    '-G "Visual Studio 16 2019"',
    '-A "x64"'
])

I receive an error:

CMake Error: Could not create named generator  "Visual Studio 16 2019"

Why it happens and how to fix it?

PS: this is not duplicate of any questions, this is new

Update1: When I change generator line to the

'-G Visual Studio 16 2019'

I see the followed error:

CMake Error: Could not create named generator  Visual Studio 16 2019

So I think it is not doublequotes fall

Upvotes: 1

Views: 1848

Answers (3)

Jaycee Chow
Jaycee Chow

Reputation: 1

I tried the following two commands:

echo_cmd = ["echo", '"Visual Studio 16 2019"']
subprocess.run(echo_cmd, check=True)

the result is "Visual Studio 17 2022".

echo_cmd = ["echo", "Visual Studio 16 2019"]
subprocess.run(echo_cmd, check=True)

the result is Visual Studio 17 2022.

So that argument your CMake received is a string containing quotes, but it expects no quotes at all.

Upvotes: 0

metal
metal

Reputation: 6332

For me, a similar problem was resolved by removing the quotes within the quotes in Python, as hinted at in @Tsyvarev's comment above. IOW:

subprocess.call(['cmake', '-G', '"Visual Studio 16 2019"']) # Fails
subprocess.call(['cmake', '-G', 'Visual Studio 16 2019'])   # Succeeds

Or if you want one generator arg:

subprocess.call(['cmake', '-G"Visual Studio 16 2019"']) # Fails
subprocess.call(['cmake', '-GVisual Studio 16 2019'])   # Succeeds

Upvotes: 1

Kevin
Kevin

Reputation: 18243

It looks like you may have two versions of CMake installed. Be sure the one used in your Python script is greater than or equal to CMake version 3.14. The Visual Studio 16 2019 generator is not available in earlier CMake versions.

You can test your CMake version used by the Python script by adding:

subprocess.call([
    '...\cmake.exe', 
    '--version'
])

Upvotes: 1

Related Questions