Navigation Menu

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/link: Linking in Windows gives "malformed pe file: unexpected flags 0xe0500020 for PE section .text" #9794

Closed
rckclmbr opened this issue Feb 6, 2015 · 7 comments
Labels
FrozenDueToAge OS-Windows WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Milestone

Comments

@rckclmbr
Copy link

rckclmbr commented Feb 6, 2015

Go version: 1.4
OS: Windows 8.1 64-bit
GOARCH: 386

Complete example:
https://github.com/rckclmbr/mingwtest

$ go build -x .
...
pack r $WORK/mingwtest.a $WORK/mingwtest/_obj/_cgo_import.8 $WORK/mingwtest/_obj/_cgo_defun.8 $WORK/mingwtest/_obj/_all.o # internal
cd .
/usr/src/go/pkg/tool/linux_amd64/8l -o $WORK/mingwtest/_obj/exe/a.out.exe -L $WORK -extld=i686-w64-mingw32-gcc $WORK/mingwtest.a
# mingwtest
/tmp/go-build284869168/mingwtest.a(_all.o): malformed pe file: unexpected flags 0xe0500020 for PE section .text
main._cgo_231fbd32956b_Cfunc_sp_error_message: _cgo_231fbd32956b_Cfunc_sp_error_message: not defined
main._cgo_231fbd32956b_Cfunc_sp_error_message: undefined: _cgo_231fbd32956b_Cfunc_sp_error_message

Compiling and linking a c program using mingw works fine, it's just the go linker that isn't working.

@ianlancetaylor ianlancetaylor added this to the Go1.5 milestone Feb 6, 2015
@minux
Copy link
Member

minux commented Feb 7, 2015 via email

@mikioh mikioh changed the title Linking in Windows gives "malformed pe file: unexpected flags 0xe0500020 for PE section .text" cmd/ld: Linking in Windows gives "malformed pe file: unexpected flags 0xe0500020 for PE section .text" Feb 8, 2015
@rckclmbr
Copy link
Author

rckclmbr commented Feb 9, 2015

Thanks, @minux

I link to the .lib because the .dll doesn't work. I tested with a test c program to be sure, and it compiles with the .lib in LD_FLAGS

$ i686-w64-mingw32-gcc -I/usr/i686-w64-mingw32/include -o test.exe test.c ./libspotify.dll
/tmp/cchhcOOM.o:test.c:(.text+0x1e): undefined reference to `sp_error_message@4'
collect2: error: ld returned 1 exit status

vs

$ i686-w64-mingw32-gcc -I/usr/i686-w64-mingw32/include -o test.exe test.c ./libspotify.lib
# compiled and runs fine

I'll keep my eye on that ticket

@rsc rsc added OS-Windows and removed os-windows labels Apr 10, 2015
@rsc rsc changed the title cmd/ld: Linking in Windows gives "malformed pe file: unexpected flags 0xe0500020 for PE section .text" cmd/link: Linking in Windows gives "malformed pe file: unexpected flags 0xe0500020 for PE section .text" Jun 8, 2015
@rsc
Copy link
Contributor

rsc commented Jun 29, 2015

Sadly, too late for Go 1.5.

@rsc rsc modified the milestones: Unplanned, Go1.5 Jun 29, 2015
@alexbrainman
Copy link
Member

@rckclmbr I tried building your program:

c:\dev\src\github.com\rckclmbr\mingwtest>go build -x .
WORK=C:\Users\brainman\AppData\Local\Temp\go-build044192842
mkdir -p $WORK\github.com\rckclmbr\mingwtest\_obj\
mkdir -p $WORK\github.com\rckclmbr\mingwtest\_obj\exe\
cd c:\dev\src\github.com\rckclmbr\mingwtest
CGO_LDFLAGS="-g" "-O2" "/libspotify/lib/libspotify.lib" "c:\\dev\\go\\pkg\\tool\\windows_amd64\\cgo.exe" -objdir "C:\\Users\\brainman\\AppData\\Local\\Temp\\go-build044192842\\github.com\\rckclmbr\\mingwtest\\_obj\\" -importpath github.com/rckclmbr/mingwtest -- -I "C:\\Users\\brainman\\AppData\\Local\\Temp\\go-build044192842\\github.com\\rckclmbr\\mingwtest\\_obj\\" -I /libspotify/include main.go
# github.com/rckclmbr/mingwtest
.\main.go:6:28: fatal error: libspotify/api.h: No such file or directory
 #include <libspotify/api.h>
                            ^
compilation terminated.

c:\dev\src\github.com\rckclmbr\mingwtest>go version
go version devel +3b7841b Mon Jun 29 01:49:05 2015 +0000 windows/amd64

c:\dev\src\github.com\rckclmbr\mingwtest>

How do I resolve this error?

Alex

@rckclmbr
Copy link
Author

@alexbrainman Look at the Dockerfile, particularly where it says "Install libspotify for win32", and adjust for windows.

You may also need to change CFLAGS and LDFLAGS in main.go to the path you extracted libspotify to.

I don't have a readily available windows install I can give you more exact instructions, let me know if that's not enough for you and I'll get you better instructions.

@alexbrainman
Copy link
Member

I tried running your C example, but no luck. I copied some files into c_test directory and modified test.c:

C:\dev\src\github.com\rckclmbr\mingwtest\c_test>dir
 Volume in drive C has no label.
 Volume Serial Number is 1354-6987

 Directory of C:\dev\src\github.com\rckclmbr\mingwtest\c_test

01/07/2015  04:45 PM    <DIR>          .
01/07/2015  04:45 PM    <DIR>          ..
13/06/2012  04:19 PM           140,632 api.h
13/06/2012  04:22 PM         1,509,376 libspotify.dll
13/06/2012  04:22 PM            62,782 libspotify.lib
01/07/2015  04:45 PM               286 test.c
               4 File(s)      1,713,076 bytes
               2 Dir(s)   7,538,417,664 bytes free

C:\dev\src\github.com\rckclmbr\mingwtest\c_test>type test.c
#include <stdio.h>
#include <api.h>

int main() {
    const char* error_message = sp_error_message(SP_ERROR_BAD_API_VERSION);
    printf("Success: %s\n", strcmp(error_message, "Invalid library version") == 0
                                ? "true" : "false");
    return 0;
}

C:\dev\src\github.com\rckclmbr\mingwtest\c_test>gcc -I. -o test.exe test.c ./libspotify.lib
C:\Users\brainman\AppData\Local\Temp\ccs0WqHK.o:test.c:(.text+0x13): undefined reference to `sp_error_message'
collect2.exe: error: ld returned 1 exit status

C:\dev\src\github.com\rckclmbr\mingwtest\c_test>

What did I do wrong?

Alex

@thanm thanm added the WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. label Feb 2, 2022
@thanm
Copy link
Contributor

thanm commented Feb 22, 2022

Closing out this bug, since it does not look actionable.

@thanm thanm closed this as completed Feb 22, 2022
@golang golang locked and limited conversation to collaborators Feb 22, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge OS-Windows WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Projects
None yet
Development

No branches or pull requests

7 participants