What's the difference between https://github.com/D-Programming-Deimos/glfw and https://github.com/DerelictOrg/DerelictGLFW3
Mike Parker via Digitalmars-d
digitalmars-d at puremagic.com
Thu Oct 23 01:22:59 PDT 2014
On 10/23/2014 2:51 AM, Edn wrote:
>
> I get this error :
>
> dmd -m64 main.d lib/glfw/glfw3.d glfw.lib
> LINK : fatal error LNK1104: cannot open file 'glfw.lib'
> --- errorlevel 1104
Did you download and compile GLFW3 as a static library? If so, then
whatever lib file that resulted needs to be somewhere the linker can
find it. IIRC, it's probably called glfw3.lib. If it's in a subdirectory
of your project, then you should refer to it by the relative path. If
you're keeping it somewhere else on your system, then you either need to
refer to it by the full path or to add it to the library path via the
command line so the linker can find it. For the latter, you need to use
whatever syntax the current linker understands (OPTLINK when compiling
32-bit on Windows, VS LINK when compiling 64-bit on Windows, or the GCC
linker on other systems).
So, let's assume you've done the following:
1) Download and compiled the C GLFW3 library and the output is called
'glfw3.lib'.
2) You've got the source set up like you show above:
-project
--main.d
--lib
---glfw
----glfw3.d
Let me make a recommendation that will make things a little more
coherent. Set up your project this way:
-project
--source
---main.d
---glfw
----glfw3.d
--lib
---glfw3.lib
Notice how I've copied glfw3 to the 'lib' directory Now I can do the
following:
cd project
dmd -m64 -Isource source/main.d source/glfw/glfw3.d lib/glfw3.lib
Notice that I passed the -I switch to tell DMD to look for imports
inside the source directory. That way, it won't try to use 'source' as a
package name. If I were compiling inside the source directory (i.e. cd
project/source) I wouldn't need to do that.
Let's say you want to use glfw3.lib with multiple projects and want to
have it in a common location. Then the project structure will be the
same, but now without the 'lib' directory. So let's say you've copied
glfw3.lib to somewhere like C:\libs. Then you can do this:
cd project
dmd -m64 -Isource -L/LIBPATH:C:\libs source/main.d source/glfw/glfw3.d
glfw3.lib
The -L switch tells dmd to pass whatever follows it to the linker.
/LIBPATH is how you tell the VS linker where to look for libraries (I
haven't tested this myself, but it's what the docs at [1] say). Now,
when it encounters glfw3.lib, it will search in that path. If you were
compiling on Linux, it would look like:
-L-L/path/to/libs
The first -L is for DMD and the second is for the linker, since that's
the flag the gcc linker uses to set the library search path [2].
And with 32-bit compilation on Windows using OPTLINK, it looks even
different [3]:
-L+C:\libs
You always need to be aware that the compiler can parese imports it
can't find & can't compile source you don't tell it to, and the linker
can't link libraries it can't find. When you're dealing with multiple
source files and libraries, compiling on the command line can be very
burdonsome, which is why build tools exist. Something like DUB makes
this all go away. Then building (usually) becomes as easy as:
cd project
dub build
I'm not recommending you switch to DUB right now, since understanding
command line compilation is an important skill, but once you *are*
comfortable with it, switching to DUB will make your life easier.
[1] http://msdn.microsoft.com/en-us/library/1xhzskbe.aspx
[2] https://gcc.gnu.org/onlinedocs/gcc/Directory-Options.html
[3]
http://www.prowiki.org/wiki4d/wiki.cgi?D__Tutorial/CompilingLinkingD#PassingsearchdirectoriesforstaticlibraryfilestoOptlink
More information about the Digitalmars-d
mailing list