Linking to MSVC dll in windows with Rust

I’m trying to link with a simple C DLL on windows against Rust library

My DLL is .h

extern "C" {
    void say_hello(const char* s);


#include <stdio.h>

void say_hello(const char* s) {
    printf("hello world");

My Rust file

#[link(name="CDbax", kind="static")]
extern "C" {
    fn say_hello(s: *const libc::c_char) -> () ;

Linking fails by giving an error with one of the data symbols

error: linking with `gcc` failed: exit code: 1
note: "gcc" "-Wl,--enable-long-section-names" "-fno-use-linker-plugin" "-Wl,--nxcompat" "-Wl,--large-address-aware" "-shared-libgcc" "-L" "C:Program Files (x86)Rust 1.2binrustlibi686-pc-windows-gnulib" "e:RustDBToolsDBAnalyticstargetdebugDBAnalytics.o" "-o" "e:RustDBToolsDBAnalyticstargetdebugDBAnalytics.dll" "e:RustDBToolsDBAnalyticstargetdebugDBAnalytics.metadata.o" "C:Program Files (x86)Rust 1.2binrustlibi686-pc-windows-gnuliblibstd-11582ce5.rlib" "C:Program Files (x86)Rust 1.2binrustlibi686-pc-windows-gnuliblibcollections-11582ce5.rlib" "C:Program Files (x86)Rust 1.2binrustlibi686-pc-windows-gnuliblibrustc_unicode-11582ce5.rlib" "C:Program Files (x86)Rust 1.2binrustlibi686-pc-windows-gnuliblibrand-11582ce5.rlib" "C:Program Files (x86)Rust 1.2binrustlibi686-pc-windows-gnulibliballoc-11582ce5.rlib" "C:Program Files (x86)Rust 1.2binrustlibi686-pc-windows-gnulibliblibc-11582ce5.rlib" "C:Program Files (x86)Rust 1.2binrustlibi686-pc-windows-gnuliblibcore-11582ce5.rlib" "-L" "e:RustDBToolsDBAnalyticstargetdebug" "-L" "e:RustDBToolsDBAnalyticstargetdebugdeps" "-L" "C:Program Files (x86)Rust 1.2binrustlibi686-pc-windows-gnulib" "-L" "e:RustDBToolsDBAnalytics.rustbini686-pc-windows-gnu" "-L" "e:RustDBToolsDBAnalyticsbini686-pc-windows-gnu" "-Wl,-Bstatic" "-Wl,--whole-archive" "-l" "CDbax" "-Wl,--no-whole-archive" "-Wl,-Bdynamic" "-l" "ws2_32" "-l" "userenv" "-l" "advapi32" "-shared" "-l" "compiler-rt"
note: Warning: corrupt .drectve at end of def file
Cannot export ??_C@_0M@LACCCNMM@hello?5world?$AA@: symbol not found

The library is build on MSVC2013 as a simple static dll. The string “hello world” is in the data section, so I wouldn’t expect it to cause a link error. Are there some specific settings I need to be aware about when linking with C libraries on windows?

Btw it’s 32bit MSVC lib.

Source: dll

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.