wabt-sys compile: error: CMAKE_PROJECT_VERSION was not declared in this scope on Ubuntu 18.04 LTS

Want to help support this blog? Try out Oh Dear, the best all-in-one monitoring tool for your entire website, co-founded by me (the guy that wrote this blogpost). Start with a 10-day trial, no strings attached.

We offer uptime monitoring, SSL checks, broken links checking, performance & cronjob monitoring, branded status pages & so much more. Try us out today!

Profile image of Mattias Geniar

Mattias Geniar, November 23, 2020

Follow me on Twitter as @mattiasgeniar

When trying to compile WebAssembly (wabt-rs) for a dependent package, it failed on Ubuntu 18.04 LTS due to this error message.

wabt-sys-0.8.0/wabt/src/option-parser.cc: In lambda function:
    error: ‘CMAKE_PROJECT_VERSION’ was not declared in this scope
    printf("%s\n", CMAKE_PROJECT_VERSION);
make[2]: *** [CMakeFiles/wabt.dir/src/option-parser.cc.o] Error 1
make[1]: *** [CMakeFiles/wabt.dir/all] Error 2
make: *** [all] Error 2
thread 'main' panicked at '
command did not execute successfully, got: exit code: 2

The error appears to come from the fact that CMAKE_PROJECT_VERSION isn’t defined in the source headers of the compilation. The problem is caused by the cmake version on the system:

$ cmake --version
cmake version 3.10.2

CMake suite maintained and supported by Kitware (kitware.com/cmake).

That version (or any version below v3.12.0) generates a header file that looks like this:


Whereas the project that’s compiling, expects it look like this:

#define CMAKE_PROJECT_VERSION "1.0.13"

One solution would be to upgrade cmake to a later version, but depending on your distribution that may not be very convenient (due to dependencies etc.).

In my case, I manually added the header file. The error occurred on line /root/.cargo/registry/src/github.com-1ecc6299db9ec823/wabt-sys-0.8.0/wabt/src/option-parser.cc according to my error message, so I modified that file and added the definition to the very top.

$ more /root/.cargo/registry/src/github.com-1ecc6299db9ec823/wabt-sys-0.8.0/wabt/src/option-parser.cc
 * Copyright 2016 WebAssembly Community Group participants
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *     http://www.apache.org/licenses/LICENSE-2.0
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * See the License for the specific language governing permissions and
 * limitations under the License.

#define CMAKE_PROJECT_VERSION "1.0.13"

#include "src/option-parser.h"

I added that #define CMAKE_PROJECT_VERSION "1.0.13" line, just above the first include statement.

After that, I re-ran the compile and it went through without a problem.

Want to subscribe to the cron.weekly newsletter?

I write a weekly-ish newsletter on Linux, open source & webdevelopment called cron.weekly.

It features the latest news, guides & tutorials and new open source projects. You can sign up via email below.

No spam. Just some good, practical Linux & open source content.