[opensuse-packaging] Re: Weird "undefined reference" only for TW x64
On Thursday, April 2, 2020 1:19:49 PM CEST Martin Liška wrote:
Ok, can you please send a simple reproducer which we can discuss? I haven't caught the beginning of this discussion.
Thank you, Martin
Sure, will try. Stefan -- Stefan Brüns / Bergstraße 21 / 52062 Aachen phone: +49 241 53809034 mobile: +49 151 50412019
On Thursday, April 2, 2020 1:22:01 PM CEST Stefan Brüns wrote:
On Thursday, April 2, 2020 1:19:49 PM CEST Martin Liška wrote:
Ok, can you please send a simple reproducer which we can discuss? I haven't caught the beginning of this discussion.
Thank you, Martin
Sure, will try.
Stefan
for file in *.h *.cpp; do echo -e "---" ; cat $file ; done --- // a.h class A { public: int a1(int i); int a2(int i); private: int m = 5; }; --- // a.cpp #include "a.h" inline int A::a1(int i) { return m + i; } int A::a2(int i) { return 2 * m + i; } --- #include "a.h" int main(int argc, char* argv[]) { A a; int r = a.a1(2); r += a.a2(3); return r; } $> g++ -c a.cpp; g++ -c main.cpp; g++ *.o -o test /usr/lib64/gcc/x86_64-suse-linux/9/../../../../x86_64-suse-linux/bin/ld: main.o: in function `main': main.cpp:(.text+0x23): undefined reference to `A::a1(int)' collect2: error: ld returned 1 exit status If I remove the "inline", it works. If I change the definition to "inline int A::a(long int i) { return m + i; }, the compiler bails out with: --- a.cpp:4:12: error: no declaration matches ‘int A::a1(long int)’ 4 | inline int A::a1(long int i) { | ^ In file included from a.cpp:2: a.h:5:6: note: candidate is: ‘int A::a1(int)’ 5 | int a1(int i); | ^~ a.h:2:7: note: ‘class A’ defined here 2 | class A | ^ --- so obviously it can match the inline definition to the non-inline declaration. Kind regards, Stefan -- Stefan Brüns / Bergstraße 21 / 52062 Aachen phone: +49 241 53809034 mobile: +49 151 50412019
participants (1)
-
Stefan Brüns