x86_64-w64-mingw32/bin/ld.exe: cannot find -lscrap_sys
Hello.
I have been trying to compile the go-scrap program on windows and I had the following error
go-scrap>go run ./example/screenshot github.com/cretz/go-scrap C:/Program Files/mingw-w64/x86_64-8.1.0-posix-seh-rt_v6-rev0/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lscrap_sys collect2.exe: error: ld returned 1 exit status.
As far as I can understand, the compiler is looking for the scrap-sys library but can't find it.
How can I do to solve the error?
I have had the same detail compiling the application on Linux.
/go/go-scrap$ go build ./example/screenshot github.com/cretz/go-scrap /usr/bin/ld: cannot find -lscrap_sys collect2: error: ld returned 1 exit status
Thanks
Did you follow the readme directions exactly, including running the Rust project build first?
The steps I have taken are the following:
go get -d github.com/cretz/go-scrap
cd scrap-sys cargo build --release
Finished release [optimized] target(s) in 0.04s
cd .. rustup default stable-x86_64-pc-windows-gnu info: using existing install for 'stable-x86_64-pc-windows-gnu' info: default toolchain set to 'stable-x86_64-pc-windows-gnu'
stable-x86_64-pc-windows-gnu unchanged - rustc 1.40.0 (73528e339 2019-12-16)
go run ./example/screenshot
C:/Program Files/mingw-w64/x86_64-8.1.0-posix-seh-rt_v6-rev0/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lscrap_sys collect2.exe: error: ld returned 1 exit status
Will I be skipping any steps?
Hrmm, haven't looked at this project in a bit, but maybe go build instead of go run. Otherwise, there's something not putting that library on the library path. Not sure when I'll be able to debug otherwise.
I was install these tool package in ubuntu20.04 and mac air, but still not work.... #6
@joalzamora I ran into this issue as well, and it was because I had to build the cargo project for the module, not the normal go path src directory. After I installed it for the module I had to go here to build the package and it ran correctly:
%GOPATH%\pkg\mod\github.com\cretz\[email protected]\scrap-sys
x86_64-w64-mingw32/bin/ld.exe: cannot find -lscrap_sys #4
Section 1: environment
- windows 10
- x86_64-w64-mingw32 or x86_64_Cygwin
Section 2: abstract:
- gcc -shared -->create shared library:
-
linux
gcc -shared -o libmymath.so sub.o add.o
-
windows
gcc -shared -o libmymath.dll add.o sub.o
Section 3: step by step
-
首先我们将源代码编译为目标文件: gcc -fPIC -c add.c sub.c 执行完毕后会生产add.o和sub.o文件
-
linux gcc -shared -o libmymath.so sub.o add.o -
windows gcc -shared -o libmymath.dll add.o sub.o执行完后,会创建一个libmymath.so动态链接库文件, so是 Shared Object 的缩写,即可以共享的目标文件。
-
用动态库编译主程序 gcc -o main -lmymath -L./ main.c # relative path or gcc -Wall -o test main.c -lmymath -Lf:/gitee/play-ground/c.xxxxxx/shared_lib/libs # absolute path
-
执行 4.1 windows and linux 加动态库路径到环境变量 powershell: $env:PATH="$env:PATH;./so_path" cmd: set PATH=%PATH%;C:\your\path\here
shell: export PATH="$PATH:./so_path"4.2 添加动态库路径后就可以正常执行exe 如果每添加动态库路径到环境变量执行exe没有任何提示或找不到so .\test.exe
Section 4: Reference
cygwin : Linker doesn't find shared library - Stack Overflow