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/go: Wndows: Linking .dll files compiles fine but throws error during runtime #23897
Comments
I suspect Windows will search your 'lib folder', if you help Windows and add 'lib folder' to you PATH. Alex |
@alexbrainman Yes I figured that out, my concern is, will it not be difficult to add a new path every time I code a new project using some 3rd party .dll file ? Shouldn't the built programs automatically search paths added in LDFLAGS ? because that's what normally happens in other languages I believe. Let's say C for example, when you compile a program using gcc using -L and -l flag it automatically fetches the dynamic library files from path specified using -L during runtime. |
Please read https://msdn.microsoft.com/en-us/library/windows/desktop/ms682586(v=vs.85).aspx for where and the order windows searches for dlls. I have never seen C/C++/C# look for dlls in the -L path at runtime. It will only look for the import library or static link libraries at the -L path. |
@AlexRouSg sorry for the miss quote , I would like to correct, C fetches the static link library from the -L path. So I've also created a static link library keyboard.a in the same lib folder, is there a possibility to make go fetch this static library during runtime ? I am new to go so trying to figure out a few things. So, I am just trying to figure out a way to link the C libraries with my go code with out need to manually set paths by the user. |
Static link libraries are linked at compile time (C also does this), there is nothing to load at runtime. Just make sure you are setting the right flags to link the static lib and not the dynamic lib. |
@AlexRouSg can you help me figure out which flags to use for static linking? or post a link to relevant documentation or tutorial ? I've tried building using |
At this point I think it's pretty clear this is not a bug so I suggest you to ask around in the proper place for help as the issue tracker is not normally used for asking questions. https://github.com/golang/go/wiki/Questions If keyboard is your own project, since you want to static link anyway, you could just put the C source files into the same folder as your go files and they will be compiled together without having to set any import or link options. |
Closing, because it is not a bug. Alex |
Please answer these questions before submitting your issue. Thanks!
What version of Go are you using (
go version
)?go version go1.10 windows/386
Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (
go env
)?Windows 10, 64 bit
What did you do?
Tried to link a cutom C library using
If possible, provide a recipe for reproducing the error.
A complete runnable program is good.
A link on play.golang.org is best.
What did you expect to see?
The built .exe file to run
What did you see instead?
The program compiles/builds with out any error but throws an error at runtime(i.e while executing the .exe file) "cannot find libkeybaord.dll", but works/runs fine if the libkeybaord.dll is placed in the same directory as the .go file, so the issue here is I want to understand why its unable to search/locate libkeybaord.dll file present in the 'lib folder' during runtime whereas it is able to locate the libkeyboard.dll in 'lib' folder and build successfully during compile time.
Directory structure:
src
|_hello.go
|_lib
----|_keyboard.h
----|_keyboard.c
----|_libkeyboard.dll
The text was updated successfully, but these errors were encountered: