473,322 Members | 1,403 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

exporting a function from a static library.

I am interested in using my static lib to create a dll (implicitly linking). which means I need to (in vs2008) create a dll project that should generate the following:

1. header file (which have exported function declarations. These are simple wrappers to actual functions in the static lib and are using __declspec(dllexport) which are in the dll centric .cpp file)
2. import lib which will be made as a result of creating the dll
3. the actual dll which is created.

Now this is what I have:
I have made a test program that will utilize the above dll(including the import lib/header files) to test it. in this I have included all the three items. now the exe compiles/links without issue. however in the main.cpp when i call the exported functions they seem to see the exported dlls...but can't seem to execute the static library functions which they wrap.

question:
1. how do I get them to see those functions?
2. is there an easier way to do this such that I still share my static library but now if anyone wants to create a dll they can because I have added "the exported function capability" to my static lib? OR do I just need to provide them with a imported library from my dll which has all my static library obj files as well? (i thought I did that when i made my dll but maybe just adding that as a reference to create the dll in vs2008 does not work??


update: i was able to use the extern C in the exe to finally get to see the dll function being exported.

so, the wrapper works in the sense that i can now call it in the exe but i am not able to execute the static lib function inside that wrapper. i have provided a sample of one of the wrappers below


thanks
Nov 14 '11 #1
8 12167
Banfa
9,065 Expert Mod 8TB
Show us one of your wrapper functions.
Nov 15 '11 #2
//wrapper in dll .cpp file

extern "C" __declspec(dllexport) bool code_generate_dll(const char* seed, char * output)
{
//making call to static lib function
return code_gen(seed,output);

};


above is an example of one of the functions in the dll implementation.

i was researching and came across this...
http://support.microsoft.com/kb/141459

would this apply to me then? if so how do i implement the linker export in my case. I am just trying to do due diligence as much as i am able to resolve this issue.

thanks
Nov 15 '11 #3
Banfa
9,065 Expert Mod 8TB
I do not think that knowledge base article applies to you at all. That is talking about exporting functions in a static library directly from a DLL but you are not doing that you are wrapping the functions in the static library. The function should get included when you compile the DLL since it should be unable to compile without including them.

What do you mean by "can't seem to execute the static library functions"?

Presumably you create a program that imports your DLL and calls code_generate_dll. So what happens when you compile/run that program?
Nov 15 '11 #4
so basically what happens is that it sees the exported dll function code_generate_dll and executes it (i put in some couts in there which work. however when i place the static library function which it is supposed to call then it that bit of code is not working. in other words the static library function that I am trying to indirectly export via the wrapper in the dll is not executing).

so the exe can see the exported code_generate_dll. it executes some of the instructions there but won't exe the static library function. that is the part that baffles me. if i was able to create the dll WITH the static library linked how come the dll wrapper function can't execute the static library function call.


i just wanted to make sure you understood. my wrappers which i need to export are in dll. so the implementation is there and in the dll i am calling the static library function. seems to me there is a problem where the dll can't seem to link to the static lib. in vs2008 i just drag and drop the static lib and thats how it works.

i also removed the middle man dll and just directly called the static lib from the exe and that works when i run it with the static lib directly. so the lib is good as well..
Nov 15 '11 #5
Banfa
9,065 Expert Mod 8TB
This sounds odd if the static library is called in the DLL either
  • The DLL with fail of link if the static library is unavailable for some reason
  • When the DLL function is called from your program it will invoke the static library function.

But, if I understand, you are saying that the DLL builds but the static library function is not called.

You haven't said how you know the static library isn't called.

I would say it is time to break out the debugger and step through the code of the dll as it runs, see what happens when it gets to that function call.
Nov 16 '11 #6
ok so i am stupid. but this is how you learn i guess. basically i was making changes and not updating my dll file that the exe was using....i hate myself!!!!!! in other words the dll file that the exe was using was an older one and not the latest one.
Nov 16 '11 #7
Banfa
9,065 Expert Mod 8TB
That sort of error catches out everyone every now and then.

Expect to make it once every 2 - 3 years for the rest of your life :D
Nov 16 '11 #8
i can't believe it!!! but man tough lesson. heheh
Nov 16 '11 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: mccoyn | last post by:
I'm porting an old project to use .NET. When I try to link in a static library (.lib) that has a single managed class in it. I get the following errors: LINK : error LNK2020: unresolved token...
4
by: jr | last post by:
I am working in VC++ so this may be microsoft specific though I don't think so. Excuse me if it is. Assuming it isn't, can someone generally explain the purpose of having both - is it purely a...
1
by: rahul | last post by:
Hi, I am working on developing a C++ application and caught with a strange issue: I am having 4 dynamic libraries for e.g. a.dll, b.dll, c.dll and d.dll. Each of these is linked with a static...
1
by: Vijai Kalyan | last post by:
I am not sure if this OT, but I will go ahead and post. If it has to be posted elsewhere let me know. -vijai. ------ I have a class declared as follows: #pragma once // a simple reference...
3
by: mpatnam | last post by:
I have an executable which links to a static library (.a). I want to provide a hook by overriding a function part of this static library. Eg: I have a function "int blkstart(int i)" in this static...
4
by: newest newbie | last post by:
I'm new to using c#, but what I'm trying to do is create a library control containing a form which in turn contains a Windows application that I have defined in another library. I'm able to do...
15
by: Notre Poubelle | last post by:
Hello, I have a large legacy MFC application. As is typical, there is an executable along with several MFC DLLs. One of these DLLs is created by staticly linking in many libraries resulting in...
6
by: Notre Poubelle | last post by:
Hello, I have a strange situation where I'm trying to export a function in a class, but it won't get exported. I actually have a couple of header and cpp files. Each pair of header and cpp...
6
by: =?Utf-8?B?R29yZG8=?= | last post by:
Hello everyone, I've been trying for some time now to move to C++/CLI, but I have several large legacy C++ static libraries I need to use. When I set up a simple solution with a C++/CLI Winforms...
6
by: Even | last post by:
Hi all, As far as I know, relative address will be assigned by program at link time.Right? Ok, here we go. So if we use a static library, it will give the program an relative address(i mean...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.