开发者

C++ - How do i link a C++ resource?

I need to use functions in a compiled C++ resource i have.

How can i use the functions in the compiled resource and have the main program use this library i have?

I have this code:

log("INFO","TH开发者_运维百科IS IS A TEST MESSAGE");

That should pull the function from the file i have. This


Update (old answer removed)

Since you have elaborated on the need to load pre-compiled code in through "plugins". This is typically done through a mechanism known as "dynamic loading". In Windows, this is accomplished through the use of DLL (Dynamic Link Libraries) files. DLL files are libraries of compiled code that a running program "load in" on demand.. The running program can load the DLL and query for addresses to function pointers with known names. For example, a "logging" DLL may export a "Log" function. And if someone else wants to provide an alternate implementation (and can register the path to their DLL with the program in some sort of configuration file), they merely have to supply their own DLL which exports the same set of functions with the exact same signature. And there are useful abstractions known as COM for loading (C++) interfaces, but I digress.

In Unix operating systems, the equivalent of DLLs is known as "shared libraries" or ".so" files.

Here's some relevant links:

http://en.wikipedia.org/wiki/Dynamic-link_library

http://www.yolinux.com/TUTORIALS/LibraryArchives-StaticAndDynamic.html

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜