[cfe-dev] clang doesn't compile simple code
fprijate
prijatelj.francek at gmail.com
Mon Apr 28 13:26:37 PDT 2014
Hi
Here is simple example and the description of the problem.
--- main.c ----
#include <stdio.h>
#include "dll.h"
int main(void)
{
hello("World");
return 0;
}
---- dll.h -------------
#ifndef DLL_H
#define DLL_H
#ifdef BUILDING_DLL
#define MY_DLL __declspec(dllexport)
#else
#define MY_DLL __declspec(dllimport)
#endif
void MY_DLL hello(const char *s);
#endif
---- dll.c -------------
#include <stdio.h>
#include "dll.h"
void hello(const char *s)
{
printf("Hello %s\n", s);
}
---- build.bat -----
clang -c -DBUILDING_DLL dll.c
clang -shared -o dll.dll dll.o -Wl,--out-implib,libdll.a
clang -c main.c
clang -o main.exe main.o -L. -ldll
-----------------------------------
Error:
Cannot export _hello: symbol not found
D:\mingw-builds\x32-4.8.1-posix-dwarf\mingw32\bin\ld.exe: warning: cannot
find entry symbol DllMainCRTStartup; defaulting to 623c1000
clang.exe: error: linker command failed with exit code 1 (use -v to see
invocation)
If i compile with gcc everything is OK
gcc -c -DBUILDING_DLL dll.c
gcc -shared -o dll.dll dll.o -Wl,--out-implib,libdll.a
gcc -c main.c
gcc -o main.exe main.o -L. -ldll
I can even create libdll with gcc and rest with clang and everything is OK.
gcc -c -DBUILDING_DLL dll.c
gcc -shared -o dll.dll dll.o -Wl,--out-implib,libdll.a
clang -c main.c
clang -o main.exe main.o -L. -ldll
So there is no problem with __declspec(dllimport).
The problem is in wrong COFF produced with: clang -c -DBUILDING_DLL dll.c
Or in other words problem lies __declspec(dllexport).
regards
FranĨek
--
View this message in context: http://clang-developers.42468.n3.nabble.com/clang-doesn-t-compile-simple-code-tp4038903p4039124.html
Sent from the Clang Developers mailing list archive at Nabble.com.
More information about the cfe-dev
mailing list