Skip to content

Instantly share code, notes, and snippets.

@retep998
Last active August 15, 2016 23:02
Show Gist options
  • Save retep998/a6047c6b03dfed5cc8a5d3e114316268 to your computer and use it in GitHub Desktop.
Save retep998/a6047c6b03dfed5cc8a5d3e114316268 to your computer and use it in GitHub Desktop.
int bunny = 273;
int rabbit() { return 273; }
> cl /c bar.c ; lib 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) Library Manager Version 14.00.24213.1
Copyright (C) Microsoft Corporation. All rights reserved.
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 __imp_rabbit referenced in function main
foo.obj : error LNK2019: unresolved external symbol __imp_bunny referenced in function main
foo.exe : fatal error LNK1120: 2 unresolved externals
#include <stdio.h>
__declspec(dllimport) 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