This is the mail archive of the
cygwin
mailing list for the Cygwin project.
build an executable with .lib created by vc
- From: "Yu-Cheng Chou" <cycchou at ucdavis dot edu>
- To: cygwin at cygwin dot com
- Date: Fri, 11 Mar 2005 18:33:51 -0800 (PST)
- Subject: build an executable with .lib created by vc
Hi,
I have a test1.lib created by the microsoft visual c++ compiler.
test1.lib contains only one function test1(), which prints out "Hello from
test1".
The other file I have is main.c, which prints out "Call Test1", call test1
() and prints out "Return Test1".
---------------------------------------------------------------------------
/* test1.c */
#include <stdio.h>
__declspec(dllexport)
void test1(void) {
printf("Hello from test1()\n");
}
---------------------------------------------------------------------------
#Makefile for creating test1.lib
target: test1.dll
test1.dll:
cl -c /MD test1.c
link /out:test1.dll /DLL test1.obj
clean:
rm -rf test1.dll test1.obj test1.lib
---------------------------------------------------------------------------
/* main.c */
#include <stdio.h>
int main() {
printf("Call Test1\n");
test1();
printf("Return Test1\n");
return 0;
}
---------------------------------------------------------------------------
#Makefile for creating main.exe in cygwin using mingw libraries and headers
target: main.exe
main.exe: main.o test1.lib
gcc -mno-cygwin -o main.exe main.o test1.lib
main.o: main.c
gcc -mno-cygwin -c main.c
clean:
rm -rf main.exe *.o
---------------------------------------------------------------------------
output:
$ ./main.exe
Call Test1
Return Test1
Hello from test1()
---------------------------------------------------------------------------
"Hello from test1()" should be between "Call Test1" and "Return Test1".
In the first makefile, I use /MD option to link with MSVCRT.LIB. But in
the second makefile used in cygwin, I have no idea how to correctly link
with MSVCRT.LIB using gcc -mno-cygwin.
So, is that the reason why the output order is incorrect?
And how to link with MSVCRT.LIB correctly in cygwin using gcc or gcc -mno-
cygwin?
Thanks
--
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
Problem reports: http://cygwin.com/problems.html
Documentation: http://cygwin.com/docs.html
FAQ: http://cygwin.com/faq/