473,385 Members | 1,569 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,385 software developers and data experts.

What is wrong with this dll import code?

Hi When I try to compile the following code I get an error:
[Linker error: undefined reference to `_imp__CreatePort@4'
....
<code>
#include <cstdlib>
#include <iostream>
#include "sDriverDLL.h"

using namespace std;

char * EXTERN InttoStr(int n, char * buff, int radix);
#ifdef __cplusplus
extern "C"
{
#endif //*/
int EXTERN CreatePort(char * PrtName);
int EXTERN OpenPort();
int EXTERN ReadaPacket(char * Packet);
int EXTERN ReadaTag(char * TagStr);
int EXTERN ClosePort();
int EXTERN FreePort();
#ifdef __cplusplus
}
#endif
//*/
int main(int argc, char *argv[])
{
cout << "starting... Creating COMPORT1";
int x = CreatePort("COM1");
}
</code>

I'm using Dev-C++ (minGW compiler) on Windows XP.

In the "sDriverDLL.h" file EXTERN is is declared as follows:
<code>
#if BUILDING_DLL
#define EXTERN __declspec (dllexport) __stdcall
#else /* Not BUILDING_DLL */
#define EXTERN __declspec (dllimport) __stdcall
#endif /* Not BUILDING_DLL */
</code>

The header file also includes the whole section:
<code>
#ifdef __cplusplus
extern "C"
{
#endif //*/
int EXTERN CreatePort(char * PrtName);
.....
#ifdef __cplusplus
}
#endif
</code>

I can actually import the .dll file into Delphi (!), but can't seem to
import it into C++ itself. What am I missing?

Thanks
Chavoux

Mar 17 '06 #1
2 2409
To clarify my problem...
As I understand it, C++ mangles the function names when compiling
(i.e. "CreatePort" becomes "_imp__CreatePort@4"). Declaring the
functions in a
"#ifdef __cplusplus
extern "C"
{
#endif //*/
....
#ifdef __cplusplus
}
#endif"
block, should force the compiler to export it as "C" functions, without
any name mangling.

The linker cannot find the mangled C++ names in the .dll because it
doesn't exist in the .dll (because of the above code block).

However, I redeclare the functions locally in a similar "C" block, but
the linker still looks for the mangled C++ function names. How do I get
it not to do this?

Any ideas?
Chavoux

Mar 17 '06 #2
On 17 Mar 2006 04:23:09 -0800, Ch*****@gmail.com wrote in
comp.lang.c++:
Hi When I try to compile the following code I get an error:
[Linker error: undefined reference to `_imp__CreatePort@4'


[snip]

Ask in news:comp.os.ms-windows.programmer.win32. DLLs are a mechanism
of your operating system, not anything defined by the C++ language.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://c-faq.com/
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html
Mar 18 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: lawrence | last post by:
I'm nervous this method is not doing what I assumed it was doing. Does it not create objects, store them in an array, and check that array to see if a requested class has already been instantiated,...
220
by: Brandon J. Van Every | last post by:
What's better about Ruby than Python? I'm sure there's something. What is it? This is not a troll. I'm language shopping and I want people's answers. I don't know beans about Ruby or have...
4
by: John Dean | last post by:
Hi I have been reading quite a lot of Python source code recently and I have come across a particular construct which I don't understand. I would be grateful if somebody could explain the reason...
226
by: Stephen C. Waterbury | last post by:
This seems like it ought to work, according to the description of reduce(), but it doesn't. Is this a bug, or am I missing something? Python 2.3.2 (#1, Oct 20 2003, 01:04:35) on linux2 Type...
1
by: Qiangning Hong | last post by:
I decide to seperate my data collection routine from my data analysis and storage program to a seperate process, so I try to use the new subprocess model in Python 2.4. The main program spawns...
9
by: Pyenos | last post by:
import cPickle, shelve could someone tell me what things are wrong with my code? class progress: PROGRESS_TABLE_ACTIONS= DEFAULT_PROGRESS_DATA_FILE="progress_data" PROGRESS_OUTCOMES=
6
by: Kid Programmer | last post by:
Hello guys. I have a question. What's wrong with my compiler. In a simple number averaging program in a GUI window have way into the project I compile the program and I get the following errors: ...
13
blazedaces
by: blazedaces | last post by:
Hey guys, how's it going today? So basically I have a program that uses hotbits (a real online random number generator based off radioactive decay) to produce truly random alphanumeric codes (Note:...
2
by: ccgrl451 | last post by:
Okay, so you probably haven't seen my previous question, whats wrong with this code. For those who have, you know what I'm talking about. If not, heres what I have to do. We have to do this...
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...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...

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.