Warum führt -Wshadow zu "linker input file unused because linking not done"

Gast #7292322
Lesenswert?

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
Gast #7292343
Lesenswert?

1
[foo@foo-desktop build]$ cmake ..
2
-- The CXX compiler identification is GNU 12.2.0
3
-- Detecting CXX compiler ABI info
4
-- Detecting CXX compiler ABI info - done
5
-- Check for working CXX compiler: /usr/bin/c++ - skipped
6
-- Detecting CXX compile features
7
-- Detecting CXX compile features - done
8
-- Configuring done
9
-- Generating done
10
-- Build files have been written to: /home/foo/test/build
11

12
[foo@foo-desktop build]$ make VERBOSE=1
13
/usr/bin/cmake -S/home/foo/test -B/home/foo/test/build --check-build-system CMakeFiles/Makefile.cmake 0
14
/usr/bin/cmake -E cmake_progress_start /home/foo/test/build/CMakeFiles /home/foo/test/build//CMakeFiles/progress.marks
15
make  -f CMakeFiles/Makefile2 all
16
make[1]: Entering directory '/home/foo/test/build'
17
make  -f CMakeFiles/mylib.dir/build.make CMakeFiles/mylib.dir/depend
18
make[2]: Entering directory '/home/foo/test/build'
19
cd /home/foo/test/build && /usr/bin/cmake -E cmake_depends "Unix Makefiles" /home/foo/test /home/foo/test /home/foo/test/build /home/foo/test/build /home/foo/test/build/CMakeFiles/mylib.dir/DependInfo.cmake --color=
20
make[2]: Leaving directory '/home/foo/test/build'
21
make  -f CMakeFiles/mylib.dir/build.make CMakeFiles/mylib.dir/build
22
make[2]: Entering directory '/home/foo/test/build'
23
[ 50%] Building CXX object CMakeFiles/mylib.dir/mylib.cpp.o
24
/usr/bin/c++   Wshadow -MD -MT CMakeFiles/mylib.dir/mylib.cpp.o -MF CMakeFiles/mylib.dir/mylib.cpp.o.d -o CMakeFiles/mylib.dir/mylib.cpp.o -c /home/foo/test/mylib.cpp
25
c++: warning: Wshadow: linker input file unused because linking not done
26
c++: error: Wshadow: linker input file not found: No such file or directory
27
make[2]: *** [CMakeFiles/mylib.dir/build.make:76: CMakeFiles/mylib.dir/mylib.cpp.o] Error 1
28
make[2]: *** Deleting file 'CMakeFiles/mylib.dir/mylib.cpp.o'
29
make[2]: Leaving directory '/home/foo/test/build'
30
make[1]: *** [CMakeFiles/Makefile2:83: CMakeFiles/mylib.dir/all] Error 2
31
make[1]: Leaving directory '/home/foo/test/build'
32
make: *** [Makefile:91: all] Error 2
Gast #7292348
Lesenswert?

Sorry, hab die Ausgabe aus einem Test ohne - vor Wshadow gepostet. Hier 
das Original:
1
[foo@foo-desktop build]$ cmake ..
2
-- The CXX compiler identification is GNU 12.2.0
3
-- Detecting CXX compiler ABI info
4
-- Detecting CXX compiler ABI info - done
5
-- Check for working CXX compiler: /usr/bin/c++ - skipped
6
-- Detecting CXX compile features
7
-- Detecting CXX compile features - done
8
-- Configuring done
9
-- Generating done
10
-- Build files have been written to: /home/foo/test/build
11

12
[foo@foo-desktop build]$ make VERBOSE=1
13
/usr/bin/cmake -S/home/foo/test -B/home/foo/test/build --check-build-system CMakeFiles/Makefile.cmake 0
14
/usr/bin/cmake -E cmake_progress_start /home/foo/test/build/CMakeFiles /home/foo/test/build//CMakeFiles/progress.marks
15
make  -f CMakeFiles/Makefile2 all
16
make[1]: Entering directory '/home/foo/test/build'
17
make  -f CMakeFiles/mylib.dir/build.make CMakeFiles/mylib.dir/depend
18
make[2]: Entering directory '/home/foo/test/build'
19
cd /home/foo/test/build && /usr/bin/cmake -E cmake_depends "Unix Makefiles" /home/foo/test /home/foo/test /home/foo/test/build /home/foo/test/build /home/foo/test/build/CMakeFiles/mylib.dir/DependInfo.cmake --color=
20
make[2]: Leaving directory '/home/foo/test/build'
21
make  -f CMakeFiles/mylib.dir/build.make CMakeFiles/mylib.dir/build
22
make[2]: Entering directory '/home/foo/test/build'
23
[ 50%] Building CXX object CMakeFiles/mylib.dir/mylib.cpp.o
24
/usr/bin/c++   -Wshadow -MD -MT CMakeFiles/mylib.dir/mylib.cpp.o -MF CMakeFiles/mylib.dir/mylib.cpp.o.d -o CMakeFiles/mylib.dir/mylib.cpp.o -c /home/foo/test/mylib.cpp
25
[100%] Linking CXX static library libmylib.a
26
/usr/bin/cmake -P CMakeFiles/mylib.dir/cmake_clean_target.cmake
27
/usr/bin/cmake -E cmake_link_script CMakeFiles/mylib.dir/link.txt --verbose=1
28
/usr/bin/ar qc libmylib.a CMakeFiles/mylib.dir/mylib.cpp.o
29
/usr/bin/ranlib libmylib.a
30
make[2]: Leaving directory '/home/foo/test/build'
31
[100%] Built target mylib
32
make[1]: Leaving directory '/home/foo/test/build'
33
/usr/bin/cmake -E cmake_progress_start /home/foo/test/build/CMakeFiles 0
Gast #7292365
Lesenswert?

Ja, scheint so^^
Ich verstehe zwar noch nicht ganz warum. Ich hab das vorher auch 
hinreichend mit -Wshadow getestet, aber jetzt läuft es.

In der Debian VM ist der Fehler aber noch da. Aber ich vermute, ich mach 
gerade etwas dummes und sollte einfach Feierabend machen und mir das 
morgen noch einmal angucken...

Danke soweit
Gast #7292694
Lesenswert?

Was auch sein kann, wenn man sich sowas aus einem Blog, PDF, E-Mail, 
etc. kopiert, einige Software ist manchmal so aufmerksam das - durch ein 
lokalisiertes unicode Zeichen zu ersetzen und ähnliche Sachen.
#7295931
Lesenswert?

Le X. schrieb:
> foo schrieb:
>> DAS ist mir jetzt wirklich peinlich...
>> Aber kaum macht man es richtig, funktioniert auch wieder alles.
>
> Da muss dir nichts peinlich sein, sowas kommt vor.
> Das sind halt die fiesen Fehler wo auch nach dem 10. Mal drüber schauen
> alles richtig aussieht.

Un die einem nur einmal passieren - danach weiß man, das aus dem Browser 
kopierter Text solche Effekte haben kann.

Oliver

Antwort schreiben

Bitte melde dich an, um einen Beitrag zu schreiben.

oder

Mit Google-Account einloggen

Die Registrierung ist kostenlos und dauert nur eine Minute.

Jetzt registrieren