Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign up[MSVC] Referencing a static from another crate doesn't seem to work #26591
Comments
tomaka
changed the title
[MSVC] Referencing a static from another crate doesn't seem to work with x86_64
[MSVC] Referencing a static from another crate doesn't seem to work
Jun 26, 2015
steveklabnik
added
the
O-windows
label
Jun 26, 2015
This comment has been minimized.
This comment has been minimized.
|
Since build scripts link to their dependencies dynamically instead of statically, this means that statics have to be properly marked with dllimport and dllexport, unlike for functions where those attributes can be left off with only a minor performance hit. MinGW's |
This comment has been minimized.
This comment has been minimized.
|
cc @alexcrichton I guess |
This comment has been minimized.
This comment has been minimized.
|
See also #7196 |
This comment has been minimized.
This comment has been minimized.
|
We currently do place dllimport on statics (and dllexport), but I haven't had a chance to investigate this thoroughly yet. I'm surprised that this doesn't work when the bootstrap works. |
This comment has been minimized.
This comment has been minimized.
|
I'm going to replace However any static + build script combination seems to trigger this problem, so it should be easy to reproduce. |
This comment has been minimized.
This comment has been minimized.
|
I have the same problem with my
But interesingly if I add |
This comment has been minimized.
This comment has been minimized.
|
Apparently using For each usage of I tried to compile a complex project (outside of a build script), and I got hundreds and hundreds of warnings, and 9 errors. In my opinion this wasn't detected earlier because warnings from the linker are simply ignored. |
This comment has been minimized.
This comment has been minimized.
Mr-Byte
commented
Jul 20, 2015
|
I'm having a similar issue during linking using |
This comment has been minimized.
This comment has been minimized.
|
OK, I had some time to investigate this and I believe I know what's going on now. The fundamental problem here is #7196 (we don't handle dllimport/dllexport properly). To recap, a constant
Now one question I had personally was "why doesn't this break everything?!" We have a huge test suite, most of which is passing on MSVC, and most of which references a static from the standard library (aka this exact situation). It turns out that if the linker already included the object file for another reason (e.g. it resolved another function) then it will detect that we're looking for What this ends up meaning is that if any other symbol from our upstream library was used, then the linker error goes away. For example if you add So, to summary, there are a number of ways to work around this:
We currently don't tag any functions with dllimport (only dllexport), so I'm currently exploring that route to see if it works for constants as well (which would fix this problem), but I vaguely remember it specifically not working before, so my hopes are not that high. Otherwise this is basically a dupe of #7196 (correctly dealing with dllimport/dllexport), so I'm going to close this in favor of that. |
alexcrichton
closed this
Jul 22, 2015
This comment has been minimized.
This comment has been minimized.
|
Ah yeah unfortunately not using dllimport didn't work. If you're importing a function from a dll and forget dllimport I think you take a small perf hit (e.g. one jump instruction) to link anyway, but if you're importing a constant from a dll and forget dllimport it just hits a link error. |
tomaka commentedJun 26, 2015
The
glutinlibrary has a build script and thekhronos_apibuild-dependency.The
khronos_apicrate does nothing except export 4 pub static items (source code here).This build script fails to compile with the MSVC++ nightlies with the following error:
The four unresolved symbols refer to the four static variables exported by
khronos_api.This only happens with the 64bits version. The 32bits build works fine.EDIT: oops, 32bits was in fact using MinGW, so nevermind.In addition to this, there are also a lot of warnings generated:
The symbols of these warnings refer to functions of the other build-dependency, which is
gl_generator. I don't really know what they mean. Maybe they are shown only because of the linking errors and would be hidden otherwise?Here is the complete log from appveyor for reference.