Skip to content

Instantly share code, notes, and snippets.

@retep998
Created August 15, 2016 23:06
Show Gist options
  • Save retep998/48d70365b101e2c36d33374f8f420287 to your computer and use it in GitHub Desktop.
Save retep998/48d70365b101e2c36d33374f8f420287 to your computer and use it in GitHub Desktop.
__declspec(dllexport) int bunny = 273;
__declspec(dllexport) int rabbit() { return 273; }
> cl /c bar.c ; link /dll bar.obj ; cl /c foo.c ; link foo.obj bar.lib
Microsoft (R) C/C++ Optimizing Compiler Version 19.00.24213.1 for x64
Copyright (C) Microsoft Corporation. All rights reserved.
bar.c
Microsoft (R) Incremental Linker Version 14.00.24213.1
Copyright (C) Microsoft Corporation. All rights reserved.
Creating library bar.lib and object bar.exp
Microsoft (R) C/C++ Optimizing Compiler Version 19.00.24213.1 for x64
Copyright (C) Microsoft Corporation. All rights reserved.
foo.c
Microsoft (R) Incremental Linker Version 14.00.24213.1
Copyright (C) Microsoft Corporation. All rights reserved.
foo.obj : error LNK2019: unresolved external symbol bunny referenced in function main
foo.exe : fatal error LNK1120: 1 unresolved externals
#include <stdio.h>
extern int bunny;
__declspec(dllimport) int rabbit();
int main() {
printf("%d", bunny);
printf("%d", rabbit());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment