go-scrap icon indicating copy to clipboard operation
go-scrap copied to clipboard

x86_64-w64-mingw32/bin/ld.exe: cannot find -lscrap_sys

Open joalzamora opened this issue 6 years ago • 6 comments

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

joalzamora avatar Dec 23 '19 15:12 joalzamora

Did you follow the readme directions exactly, including running the Rust project build first?

cretz avatar Dec 23 '19 21:12 cretz

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?

joalzamora avatar Dec 23 '19 22:12 joalzamora

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.

cretz avatar Dec 24 '19 01:12 cretz

I was install these tool package in ubuntu20.04 and mac air, but still not work.... #6

jinjin123 avatar Oct 28 '20 03:10 jinjin123

@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

jcloutz avatar Jan 16 '21 22:01 jcloutz

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:

  1. 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

  1. 首先我们将源代码编译为目标文件: gcc -fPIC -c add.c sub.c 执行完毕后会生产add.o和sub.o文件

  2. 然后使用gcc的-shared选项来表明创建一个共享库:

  • 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 的缩写,即可以共享的目标文件。

  1. 用动态库编译主程序 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

  2. 执行 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

C语言 共享库(动态库)制作

cygwin : Linker doesn't find shared library - Stack Overflow

ld269440877 avatar Aug 12 '22 13:08 ld269440877