Shared library linking works with MSVC.

pull/15/head
Jussi Pakkanen 12 years ago
parent 34f1042a7e
commit 81b478e031
  1. 9
      backends.py
  2. 13
      test cases/common/6 linkshared/libfile.c
  3. 8
      test cases/common/6 linkshared/main.c

@ -199,14 +199,17 @@ class Backend():
return commands
def build_target_link_arguments(self, deps):
def build_target_link_arguments(self, compiler, deps):
args = []
for d in deps:
if not isinstance(d, interpreter.StaticLibrary) and\
not isinstance(d, interpreter.SharedLibrary):
raise RuntimeError('Tried to link with a non-library target "%s".' % d.get_basename())
fname = self.get_target_filename(d)
fname = './' + fname # Hack to make ldd find the library.
if compiler.id == 'msvc':
if fname.endswith('dll'):
fname = fname[:-3] + 'lib'
fname = os.path.join('.', fname) # Hack to make ldd find the library.
args.append(fname)
return args
@ -671,7 +674,7 @@ class NinjaBackend(Backend):
for dep in target.get_external_deps():
commands += dep.get_link_flags()
dependencies = target.get_dependencies()
commands += self.build_target_link_arguments(dependencies)
commands += self.build_target_link_arguments(linker, dependencies)
if self.environment.coredata.coverage:
commands += linker.get_coverage_link_flags()
dep_targets = [self.get_dependency_filename(t) for t in dependencies]

@ -1,3 +1,14 @@
int func() {
#if defined _WIN32 || defined __CYGWIN__
#define DLL_PUBLIC __declspec(dllexport)
#else
#if defined __GNUC__
#define DLL_PUBLIC __attribute__ ((visibility("default")))
#else
#pragma message ("Compiler does not support symbol visibility.")
#define DLL_PUBLIC
#endif
#endif
int DLL_PUBLIC func() {
return 0;
}

@ -1,4 +1,10 @@
int func();
#if defined _WIN32 || defined __CYGWIN__
#define DLL_IMPORT __declspec(dllimport)
#else
#define DLL_IMPORT
#endif
int DLL_IMPORT func();
int main(int argc, char **arg) {
return func();

Loading…
Cancel
Save