Hallo,
wenn ich cmake eine static library bauen lasse und -Wshadow als Option
mitgebe, dann bricht der Compilevorgang ab. Ohne -Wshadow gibt es kein
Problem.
CMakeLists.txt
1 | cmake_minimum_required(VERSION 3.18)
|
2 | project(mylib LANGUAGES CXX)
|
3 |
|
4 | add_compile_options(−Wshadow)
|
5 |
|
6 | add_library(mylib STATIC mylib.cpp)
|
mylib.h
1 | #ifndef MYLIB_H
|
2 | #define MYLIB_H
|
3 |
|
4 | class Foo {
|
5 | public:
|
6 | Foo();
|
7 | int bar(int a, int b);
|
8 | };
|
9 |
|
10 | #endif
|
mylib.cpp
1 | #include "mylib.h"
|
2 | Foo::Foo() {}
|
3 | int Foo::bar(int a, int b) { return a + b; }
|
Output:
1 | [ 50%] Building CXX object CMakeFiles/mylib.dir/mylib.cpp.o
|
2 | c++: warning: −Wshadow: linker input file unused because linking not done
|
3 | c++: error: −Wshadow: linker input file not found: No such file or directory
|
4 | make[2]: *** [CMakeFiles/mylib.dir/build.make:76: CMakeFiles/mylib.dir/mylib.cpp.o] Error 1
|
5 | make[2]: *** Deleting file 'CMakeFiles/mylib.dir/mylib.cpp.o'
|
6 | make[1]: *** [CMakeFiles/Makefile2:83: CMakeFiles/mylib.dir/all] Error 2
|
7 | make: *** [Makefile:91: all] Error 2
|
Das habe ich getestet unter Manjaro und Debian mit folgenden Versionen:
Manjaro:
cmake 3.25.1
g++ 12.2.0
Debian
cmake 3.18.4
g++ 10.2.1
Was habe ich hier falsch verstanden? Nach meinem Verständnis sollte
Wshadow doch sowieso nur zur Compilezeit arbeiten und überhaupt nichts
vom Linker brauchen.
Oder stehe ich heute sehr auf dem Schlauch?
Viele Grüße