开发者

Using created DLL-file (call function from application)

I have got a dummy question. I have three C files: f1.c f2.c f3.c, which contain:

// f1.c
int f1()
{
    return 2;
}

// f2.c
int f2()
{
    return 4;
}

// f3.c
int f3()
{
    return 10;
}

I have already 3 object file, when i run the following command (i use mingc under windows7):

gcc -c f1.c f2.c f3.c

and i create dll file:

gcc f1.o f2.o f3.o -o tes开发者_JAVA技巧t1.dll -shared

using DLL Export Viewer i have opened this file:

Using created DLL-file (call function from application)

How I can use this file in my application (crossplatform)? How I can call functrion f1, f2, f3 ?

Sorry for my bad English


Assuming you have the header, the only thing that you are missing is the A archive, which the linker needs in order to figure out what a DLL provides.

Change this:

gcc f1.o f2.o f3.o -o test1.dll -shared

To this:

gcc f1.o f2.o f3.o -o test1.dll -shared -Wl,--out-implib,libtest1.a

Then, to link with the shared library, pass -ltest1 to gcc.

You will still need to recompile the library for each platform and architecture (x86, AMD64, IA64, etc.). Windows uses DLLs, but Linux uses Shared Objects, for example.

See http://www.mingw.org/wiki/sampleDLL for more information.


  1. Include the header file in the calling program.
  2. Link the calling program to the .lib file associated with the library.
  3. Make sure that the library is in the library search path.
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜