-1

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","THIS IS A TEST MESSAGE");

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

Tyler McMaster
  • 1,407
  • 2
  • 14
  • 15
  • 1
    Standard C++ has no concept of a "compiled resource." If you're talking about resources in Visual Studio, that's something outside the standard, and you'll have to deal with those yourself. – Nicol Bolas Aug 15 '11 at 04:51
  • I dont know what to call it, I'm trying to use a file i compiled in gcc or dev-C++. with another program – Tyler McMaster Aug 15 '11 at 04:51
  • possible duplicate of [embedded resource in c++](http://stackoverflow.com/questions/1074362/embedded-resource-in-c) – Nicol Bolas Aug 15 '11 at 04:52
  • What header file do i have to use? If i have to use "windows.h". Linux cant use that can it? – Tyler McMaster Aug 15 '11 at 04:54
  • I think "resource" is the wrong term here. You want to invoke a function from one SOURCE file that was implemented in another SOURCE file. Right? – selbie Aug 15 '11 at 04:55
  • I'm wanting to use a compiled source file and use its function in another source file. – Tyler McMaster Aug 15 '11 at 04:58
  • You'll need to describe your environment a little better. Linking to compiled code is done differently depending on compiler/IDE. For example, if you are using GCC then you can take a look at the [options for linking](http://gcc.gnu.org/onlinedocs/gcc/Link-Options.html) for GCC. –  Aug 15 '11 at 05:00
  • ok, I'll look at that. My idea was maybe I could use plugins with my program. – Tyler McMaster Aug 15 '11 at 05:03
  • 1
    Tyler - welcome to Stack Overflow. Asking questions is appreciated, but you need to be very crisp in how your phrase your questions so you can get the right answer. Your question said "compiled resource", which implies you are asking about how to access non-code objects. But then on inspection, we thought you were really taking about compiling and linking code across two different source files. And then after further queries, you were really talking about dynamically loading plugins of compiled code - which is completely not obvious from the original question. – selbie Aug 15 '11 at 06:11

1 Answers1

0

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

selbie
  • 100,020
  • 15
  • 103
  • 173