糟糕的reloc地址。eh_frame collect2。exe:错误:当与MinGW一起编译时,ld返回1退出状态。

时间:2020-12-27 18:33:44

After finishing installing MinGW and GCC on my system, I decided to test it out. I wrote the following 3 files:

在我的系统上安装了MinGW和GCC之后,我决定测试一下。我写了以下3个文件:

complex.h

# ifndef hjp_complex
# define hjp_complex

typedef struct _complex
{
    double real, image;
} complex;

complex complex_add( const complex a, const complex b );
complex complex_sub( const complex a, const complex b );
complex complex_mul( const complex a, const complex b );

# endif

complex.c

# include "complex.h"

complex complex_add( const complex a, const complex b ) {
    complex c = a;
    c.real += b.real;
    c.image += b.image;
    return c;
}

complex complex_sub( const complex a, const complex b ) {
    complex c = a;
    c.real -= b.real;
    c.image -= b.image;
    return c;
}

complex complex_mul( const complex a, const complex b ) {
    complex c = a;
    c.real = a.real * b.real - a.image * b.image;
    c.image = a.real * b.image + a.image * b.real;
    return c;
}

testing.c

# include <stdio.h>
# include "complex.h"

# define cmplx_out(t) printf( "%.2f + %.2fi\n", t.real, t.image )

int main() {
    complex x, g, h;
    x.real = 3;         h.real = 12;
    x.image = 12;       h.image = 3;
    cmplx_out( x );
    cmplx_out( h );
    return 0;
}

After that, compiling and executing testing.c worked fine:

之后,编译和执行测试。c工作得很好:

C:\Users\hjpotter92\Documents\Programming>gcc testing.c

C:\Users\hjpotter92\Documents\Programming>a
3.00 + 12.00i
12.00 + 3.00i

Now, when testing the functions for complex number computations (new testing.c):

现在,当测试复杂数字计算的函数时(新的test. c):

# include <stdio.h>
# include "complex.h"

# define cmplx_out(t) printf( "%.2f + %.2fi\n", t.real, t.image )

int main() {
    complex x, g, h;
    x.real = 3;         h.real = 12;
    x.image = 12;       h.image = 3;
    g = complex_mul( x, h );
    cmplx_out( g );
    g = complex_sub( x, h );
    cmplx_out( g );
    g = complex_add( x, h );
    cmplx_out( g );
    return 0;
}

And when I try to compile it:

当我试图编译时:

C:\Users\hjpotter92\Documents\Programming>gcc testing.c
C:\Users\HJPOTT~1\AppData\Local\Temp\ccwD6Lqh.o:testing.c:(.text+0x7e): undefined reference to `complex_mul'
C:\Users\HJPOTT~1\AppData\Local\Temp\ccwD6Lqh.o:testing.c:(.text+0xe8): undefined reference to `complex_sub'
C:\Users\HJPOTT~1\AppData\Local\Temp\ccwD6Lqh.o:testing.c:(.text+0x172): undefined reference to `complex_add'
c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../../mingw32/bin/ld.exe: C:\Users\HJPOTT~1\AppData\Local\Temp\ccwD6Lqh.o: bad reloc address 0x20 in section `.eh_frame'
c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../../mingw32/bin/ld.exe: final link failed: Invalid operation
collect2.exe: error: ld returned 1 exit status

Referring to a few other questions, I tried a lot of combinations:

在谈到其他几个问题时,我尝试了很多组合:

  • compiling both of them

    编译他们两人

    C:\Users\hjpotter92\Documents\Programming>gcc complex.c testing.c
    C:\Users\HJPOTT~1\AppData\Local\Temp\ccKuURyc.o:testing.c:(.text+0x7e): undefined reference to `complex_mul'
    C:\Users\HJPOTT~1\AppData\Local\Temp\ccKuURyc.o:testing.c:(.text+0xe8): undefined reference to `complex_sub'
    C:\Users\HJPOTT~1\AppData\Local\Temp\ccKuURyc.o:testing.c:(.text+0x172): undefined reference to `complex_add'
    c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../../mingw32/bin/ld.exe: C:\Users\HJPOTT~1\AppData\Local\Temp\ccKuURyc.o: bad reloc address 0x20 in section `.eh_frame'
    c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../../mingw32/bin/ld.exe: final link failed: Invalid operation
    collect2.exe: error: ld returned 1 exit status
    
  • creating assembled outputs and generating output using those:

    使用这些方法创建组装的输出和生成输出:

    C:\Users\hjpotter92\Documents\Programming>gcc -c testing.c
    
    C:\Users\hjpotter92\Documents\Programming>gcc -c complex.c
    
    C:\Users\hjpotter92\Documents\Programming>gcc complex.o testing.o
    testing.o:testing.c:(.text+0x7e): undefined reference to `complex_mul'
    testing.o:testing.c:(.text+0xe8): undefined reference to `complex_sub'
    testing.o:testing.c:(.text+0x172): undefined reference to `complex_add'
    c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../../mingw32/bin/ld.exe: testing.o: bad reloc address 0x20 in section `.eh_frame'
    c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../../mingw32/bin/ld.exe: final link failed: Invalid operation
    collect2.exe: error: ld returned 1 exit status
    

No difference in outputs is observed on passing -Wall parameter.

在传递-壁面参数上没有观察到输出的差异。

Can someone help me regarding the issue? The program seems to be pretty straightforward and there shouldn't be any problems with compiling and executing it.

有人能帮我解决这个问题吗?这个程序看起来非常简单,编译和执行时不应该有任何问题。

PS: The program works perfectly on an Arch machine:

PS:这个程序在Arch机器上是完美的:

archdesktop% gcc complex.c testing.c
archdesktop% ./a.out
0.00 + 153.00i
-9.00 + 9.00i
15.00 + 15.00i

GCC details:

GCC细节:

C:\Users\hjpotter92\Documents\Programming>gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=c:/mingw/bin/../libexec/gcc/mingw32/4.8.1/lto-wrapper.exe
Target: mingw32
Configured with: ../gcc-4.8.1/configure --prefix=/mingw --host=mingw32 --build=mingw32 --without-pic --enable-shared --enable-static --with-gnu-ld --enable-lto --enable-libssp --disable-multilib --enable-languages=c,c++,fortran,objc,obj-c++,ada --disable-sjlj-exceptions --with-dwarf2 --disable-win32-registry --enable-libstdcxx-debug --enable-version-specific-runtime-libs --with-mp=/usr/src/pkg/gmp-5.1.2-1-mingw32-src/bld --with-mpc=/usr/src/pkg/mpc-1.0.1-1-mingw32-src/bld --with-mpfr= --with-system-zlib --with-gnu-as --enable-decimal-float=yes --enable-libgomp --enable-threads --with-libiconv-prefix=/mingw32 --with-libintl-prefix=/mingw --disable-bootstrap LDFLAGS=-s CFLAGS=-D_USE_32BIT_TIME_T
Thread model: win32
gcc version 4.8.1 (GCC)

I used mingw-get to install gcc.

我使用mingw-get来安装gcc。

1 个解决方案

#1


0  

Apparently, the suggestion of using -v flag while compiling seems to compile the program without errors. Once I successfully compiled the program with -v, gcc isn't running into any errors with any of the methods I was trying before.

显然,在编译时使用-v标志的建议似乎编译程序没有错误。一旦我用-v成功地编译了这个程序,gcc就不会遇到任何我以前尝试过的方法的错误。

C:\Users\hjpotter92\Documents\Programming>gcc -v testing.c complex.c
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=c:/mingw/bin/../libexec/gcc/mingw32/4.8.1/lto-wrapper.exe
Target: mingw32
Configured with: ../gcc-4.8.1/configure --prefix=/mingw --host=mingw32 --build=mingw32 --without-pic --enable-shared --enable-static --with-gnu-ld --enable-lto --enable-libssp --disable-multilib --enable-languages=c,c++,fortran,objc,obj-c++,ada --disable-sjlj-exceptions --with-dwarf2 --disable-win32-registry --enable-libstdcxx-debug --enable-version-specific-runtime-libs --with-gmp=/usr/src/pkg/gmp-5.1.2-1-mingw32-src/bld --with-mpc=/usr/src/pkg/mpc-1.0.1-1-mingw32-src/bld --with-mpfr= --with-system-zlib --with-gnu-as --enable-decimal-float=yes --enable-libgomp --enable-threads --with-libiconv-prefix=/mingw32 --with-libintl-prefix=/mingw --disable-bootstrap LDFLAGS=-s CFLAGS=-D_USE_32BIT_TIME_T
Thread model: win32
gcc version 4.8.1 (GCC)
COLLECT_GCC_OPTIONS='-v' '-mtune=generic' '-march=pentiumpro'
 c:/mingw/bin/../libexec/gcc/mingw32/4.8.1/cc1.exe -quiet -v -iprefix c:\mingw\bin\../lib/gcc/mingw32/4.8.1/ testing.c -quiet -dumpbase testing.c -mtune=generic -march=pentiumpro -auxbase testing -version -o C:\Users\HJPOTT~1\AppData\Local\Temp\ccDBoHzE.s
GNU C (GCC) version 4.8.1 (mingw32)
        compiled by GNU C version 4.8.1, GMP version 5.1.2, MPFR version 3.1.2, MPC version 1.0.1
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
ignoring nonexistent directory "c:\mingw\bin\../lib/gcc/mingw32/4.8.1/../../../../mingw32/include"
ignoring duplicate directory "c:/mingw/lib/gcc/../../lib/gcc/mingw32/4.8.1/include"
ignoring duplicate directory "c:/mingw/lib/gcc/../../lib/gcc/mingw32/4.8.1/../../../../include"
ignoring duplicate directory "/mingw/include"
ignoring duplicate directory "c:/mingw/lib/gcc/../../lib/gcc/mingw32/4.8.1/include-fixed"
ignoring nonexistent directory "c:/mingw/lib/gcc/../../lib/gcc/mingw32/4.8.1/../../../../mingw32/include"
ignoring duplicate directory "/mingw/include"
#include "..." search starts here:
#include <...> search starts here:
 c:\mingw\bin\../lib/gcc/mingw32/4.8.1/include
 c:\mingw\bin\../lib/gcc/mingw32/4.8.1/../../../../include
 c:\mingw\bin\../lib/gcc/mingw32/4.8.1/include-fixed
End of search list.
GNU C (GCC) version 4.8.1 (mingw32)
        compiled by GNU C version 4.8.1, GMP version 5.1.2, MPFR version 3.1.2, MPC version 1.0.1
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: 767202a405449496e68a54c4eee91a28
COLLECT_GCC_OPTIONS='-v' '-mtune=generic' '-march=pentiumpro'
 c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../../mingw32/bin/as.exe -v -o C:\Users\HJPOTT~1\AppData\Local\Temp\ccc6ue9i.o C:\Users\HJPOTT~1\AppData\Local\Temp\ccDBoHzE.s
GNU assembler version 2.24 (mingw32) using BFD version (GNU Binutils) 2.24
COLLECT_GCC_OPTIONS='-v' '-mtune=generic' '-march=pentiumpro'
 c:/mingw/bin/../libexec/gcc/mingw32/4.8.1/cc1.exe -quiet -v -iprefix c:\mingw\bin\../lib/gcc/mingw32/4.8.1/ complex.c -quiet -dumpbase complex.c -mtune=generic -march=pentiumpro -auxbase complex -version -o C:\Users\HJPOTT~1\AppData\Local\Temp\ccDBoHzE.s
GNU C (GCC) version 4.8.1 (mingw32)
        compiled by GNU C version 4.8.1, GMP version 5.1.2, MPFR version 3.1.2, MPC version 1.0.1
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
ignoring nonexistent directory "c:\mingw\bin\../lib/gcc/mingw32/4.8.1/../../../../mingw32/include"
ignoring duplicate directory "c:/mingw/lib/gcc/../../lib/gcc/mingw32/4.8.1/include"
ignoring duplicate directory "c:/mingw/lib/gcc/../../lib/gcc/mingw32/4.8.1/../../../../include"
ignoring duplicate directory "/mingw/include"
ignoring duplicate directory "c:/mingw/lib/gcc/../../lib/gcc/mingw32/4.8.1/include-fixed"
ignoring nonexistent directory "c:/mingw/lib/gcc/../../lib/gcc/mingw32/4.8.1/../../../../mingw32/include"
ignoring duplicate directory "/mingw/include"
#include "..." search starts here:
#include <...> search starts here:
 c:\mingw\bin\../lib/gcc/mingw32/4.8.1/include
 c:\mingw\bin\../lib/gcc/mingw32/4.8.1/../../../../include
 c:\mingw\bin\../lib/gcc/mingw32/4.8.1/include-fixed
End of search list.
GNU C (GCC) version 4.8.1 (mingw32)
        compiled by GNU C version 4.8.1, GMP version 5.1.2, MPFR version 3.1.2, MPC version 1.0.1
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: 767202a405449496e68a54c4eee91a28
COLLECT_GCC_OPTIONS='-v' '-mtune=generic' '-march=pentiumpro'
 c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../../mingw32/bin/as.exe -v -o C:\Users\HJPOTT~1\AppData\Local\Temp\ccPq9b2h.o C:\Users\HJPOTT~1\AppData\Local\Temp\ccDBoHzE.s
GNU assembler version 2.24 (mingw32) using BFD version (GNU Binutils) 2.24
COMPILER_PATH=c:/mingw/bin/../libexec/gcc/mingw32/4.8.1/;c:/mingw/bin/../libexec/gcc/;c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../../mingw32/bin/
LIBRARY_PATH=c:/mingw/bin/../lib/gcc/mingw32/4.8.1/;c:/mingw/bin/../lib/gcc/;c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../../mingw32/lib/;c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../
COLLECT_GCC_OPTIONS='-v' '-mtune=generic' '-march=pentiumpro'
 c:/mingw/bin/../libexec/gcc/mingw32/4.8.1/collect2.exe -Bdynamic c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../crt2.o c:/mingw/bin/../lib/gcc/mingw32/4.8.1/crtbegin.o -Lc:/mingw/bin/../lib/gcc/mingw32/4.8.1 -Lc:/mingw/bin/../lib/gcc -Lc:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../../mingw32/lib -Lc:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../.. C:\Users\HJPOTT~1\AppData\Local\Temp\ccc6ue9i.o C:\Users\HJPOTT~1\AppData\Local\Temp\ccPq9b2h.o -lmingw32 -lgcc -lgcc_eh -lmoldname -lmingwex -lmsvcrt -ladvapi32 -lshell32 -luser32 -lkernel32 -lmingw32 -lgcc -lgcc_eh -lmoldname -lmingwex -lmsvcrt c:/mingw/bin/../lib/gcc/mingw32/4.8.1/crtend.o

#1


0  

Apparently, the suggestion of using -v flag while compiling seems to compile the program without errors. Once I successfully compiled the program with -v, gcc isn't running into any errors with any of the methods I was trying before.

显然,在编译时使用-v标志的建议似乎编译程序没有错误。一旦我用-v成功地编译了这个程序,gcc就不会遇到任何我以前尝试过的方法的错误。

C:\Users\hjpotter92\Documents\Programming>gcc -v testing.c complex.c
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=c:/mingw/bin/../libexec/gcc/mingw32/4.8.1/lto-wrapper.exe
Target: mingw32
Configured with: ../gcc-4.8.1/configure --prefix=/mingw --host=mingw32 --build=mingw32 --without-pic --enable-shared --enable-static --with-gnu-ld --enable-lto --enable-libssp --disable-multilib --enable-languages=c,c++,fortran,objc,obj-c++,ada --disable-sjlj-exceptions --with-dwarf2 --disable-win32-registry --enable-libstdcxx-debug --enable-version-specific-runtime-libs --with-gmp=/usr/src/pkg/gmp-5.1.2-1-mingw32-src/bld --with-mpc=/usr/src/pkg/mpc-1.0.1-1-mingw32-src/bld --with-mpfr= --with-system-zlib --with-gnu-as --enable-decimal-float=yes --enable-libgomp --enable-threads --with-libiconv-prefix=/mingw32 --with-libintl-prefix=/mingw --disable-bootstrap LDFLAGS=-s CFLAGS=-D_USE_32BIT_TIME_T
Thread model: win32
gcc version 4.8.1 (GCC)
COLLECT_GCC_OPTIONS='-v' '-mtune=generic' '-march=pentiumpro'
 c:/mingw/bin/../libexec/gcc/mingw32/4.8.1/cc1.exe -quiet -v -iprefix c:\mingw\bin\../lib/gcc/mingw32/4.8.1/ testing.c -quiet -dumpbase testing.c -mtune=generic -march=pentiumpro -auxbase testing -version -o C:\Users\HJPOTT~1\AppData\Local\Temp\ccDBoHzE.s
GNU C (GCC) version 4.8.1 (mingw32)
        compiled by GNU C version 4.8.1, GMP version 5.1.2, MPFR version 3.1.2, MPC version 1.0.1
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
ignoring nonexistent directory "c:\mingw\bin\../lib/gcc/mingw32/4.8.1/../../../../mingw32/include"
ignoring duplicate directory "c:/mingw/lib/gcc/../../lib/gcc/mingw32/4.8.1/include"
ignoring duplicate directory "c:/mingw/lib/gcc/../../lib/gcc/mingw32/4.8.1/../../../../include"
ignoring duplicate directory "/mingw/include"
ignoring duplicate directory "c:/mingw/lib/gcc/../../lib/gcc/mingw32/4.8.1/include-fixed"
ignoring nonexistent directory "c:/mingw/lib/gcc/../../lib/gcc/mingw32/4.8.1/../../../../mingw32/include"
ignoring duplicate directory "/mingw/include"
#include "..." search starts here:
#include <...> search starts here:
 c:\mingw\bin\../lib/gcc/mingw32/4.8.1/include
 c:\mingw\bin\../lib/gcc/mingw32/4.8.1/../../../../include
 c:\mingw\bin\../lib/gcc/mingw32/4.8.1/include-fixed
End of search list.
GNU C (GCC) version 4.8.1 (mingw32)
        compiled by GNU C version 4.8.1, GMP version 5.1.2, MPFR version 3.1.2, MPC version 1.0.1
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: 767202a405449496e68a54c4eee91a28
COLLECT_GCC_OPTIONS='-v' '-mtune=generic' '-march=pentiumpro'
 c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../../mingw32/bin/as.exe -v -o C:\Users\HJPOTT~1\AppData\Local\Temp\ccc6ue9i.o C:\Users\HJPOTT~1\AppData\Local\Temp\ccDBoHzE.s
GNU assembler version 2.24 (mingw32) using BFD version (GNU Binutils) 2.24
COLLECT_GCC_OPTIONS='-v' '-mtune=generic' '-march=pentiumpro'
 c:/mingw/bin/../libexec/gcc/mingw32/4.8.1/cc1.exe -quiet -v -iprefix c:\mingw\bin\../lib/gcc/mingw32/4.8.1/ complex.c -quiet -dumpbase complex.c -mtune=generic -march=pentiumpro -auxbase complex -version -o C:\Users\HJPOTT~1\AppData\Local\Temp\ccDBoHzE.s
GNU C (GCC) version 4.8.1 (mingw32)
        compiled by GNU C version 4.8.1, GMP version 5.1.2, MPFR version 3.1.2, MPC version 1.0.1
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
ignoring nonexistent directory "c:\mingw\bin\../lib/gcc/mingw32/4.8.1/../../../../mingw32/include"
ignoring duplicate directory "c:/mingw/lib/gcc/../../lib/gcc/mingw32/4.8.1/include"
ignoring duplicate directory "c:/mingw/lib/gcc/../../lib/gcc/mingw32/4.8.1/../../../../include"
ignoring duplicate directory "/mingw/include"
ignoring duplicate directory "c:/mingw/lib/gcc/../../lib/gcc/mingw32/4.8.1/include-fixed"
ignoring nonexistent directory "c:/mingw/lib/gcc/../../lib/gcc/mingw32/4.8.1/../../../../mingw32/include"
ignoring duplicate directory "/mingw/include"
#include "..." search starts here:
#include <...> search starts here:
 c:\mingw\bin\../lib/gcc/mingw32/4.8.1/include
 c:\mingw\bin\../lib/gcc/mingw32/4.8.1/../../../../include
 c:\mingw\bin\../lib/gcc/mingw32/4.8.1/include-fixed
End of search list.
GNU C (GCC) version 4.8.1 (mingw32)
        compiled by GNU C version 4.8.1, GMP version 5.1.2, MPFR version 3.1.2, MPC version 1.0.1
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: 767202a405449496e68a54c4eee91a28
COLLECT_GCC_OPTIONS='-v' '-mtune=generic' '-march=pentiumpro'
 c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../../mingw32/bin/as.exe -v -o C:\Users\HJPOTT~1\AppData\Local\Temp\ccPq9b2h.o C:\Users\HJPOTT~1\AppData\Local\Temp\ccDBoHzE.s
GNU assembler version 2.24 (mingw32) using BFD version (GNU Binutils) 2.24
COMPILER_PATH=c:/mingw/bin/../libexec/gcc/mingw32/4.8.1/;c:/mingw/bin/../libexec/gcc/;c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../../mingw32/bin/
LIBRARY_PATH=c:/mingw/bin/../lib/gcc/mingw32/4.8.1/;c:/mingw/bin/../lib/gcc/;c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../../mingw32/lib/;c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../
COLLECT_GCC_OPTIONS='-v' '-mtune=generic' '-march=pentiumpro'
 c:/mingw/bin/../libexec/gcc/mingw32/4.8.1/collect2.exe -Bdynamic c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../crt2.o c:/mingw/bin/../lib/gcc/mingw32/4.8.1/crtbegin.o -Lc:/mingw/bin/../lib/gcc/mingw32/4.8.1 -Lc:/mingw/bin/../lib/gcc -Lc:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../../mingw32/lib -Lc:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../.. C:\Users\HJPOTT~1\AppData\Local\Temp\ccc6ue9i.o C:\Users\HJPOTT~1\AppData\Local\Temp\ccPq9b2h.o -lmingw32 -lgcc -lgcc_eh -lmoldname -lmingwex -lmsvcrt -ladvapi32 -lshell32 -luser32 -lkernel32 -lmingw32 -lgcc -lgcc_eh -lmoldname -lmingwex -lmsvcrt c:/mingw/bin/../lib/gcc/mingw32/4.8.1/crtend.o