Board index » cppbuilder » Unresolved external __declspec(dllimport), and illegal instruction

Unresolved external __declspec(dllimport), and illegal instruction


2004-11-17 07:35:38 PM
cppbuilder75
Hi all,
I've never used C/C++ to write a Windows app (only console apps), and I'm
hitting an error that suggests I'm ignorantly misusing the Bcc32 compiler
("Borland C++ 5.5 for Win32" with "Turbo Incremental Link 5.00") under
WinXP.
In case it's relevant, I'm attempting to compile the Sun Java launcher
(java.c + java_md.c). I've been getting many "unresolved references" where
java_md.c calls functions in java.c, despite the presence of good-looking
function prototypes. To try to track down the problem, I merged the source
code from both files into a single source file and compiled that. All of
the unresolved reference errors went away, with the exception of one
referring to "___initenv", which appears as follows in the source:
__declspec(dllimport) char **__initenv;
int WINAPI WinMain(HINSTANCE inst, HINSTANCE previnst, LPSTR cmdline, int
cmdshow)
{
int ret;
SetThreadLocale(GetSystemDefaultLCID());
__initenv = _environ;
ret = main(__argc, __argv);
return ret;
}
What do I need to do? I've been Googling, and seen a few references to
IMPLIB and COFF2OMF, but I've done my head in trying to understand what
they're used for and how to use them...and I don't know if they're related
to my problem anyway :( I've never even built a DLL.
The compile command I'm using is as follows. I've broken it into multiple
lines here for readability:
bcc32 -5 -tW -DJAVAW -DWIN32
"-IC:\Program Files\Borland\bcc55\Include"
"-IC:\Program Files\Java\j2sdk1.4.2_03\include"
"-IC:\Program Files\Java\j2sdk1.4.2_03\include\win32"
"-LC:\Program Files\Borland\bcc55\Lib"
-DJDK_MAJOR_VERSION=\"1\"
-DJDK_MINOR_VERSION=\"4\"
"-DJAVA_ARGS={ \"heysen.common.ui.UiDialog_Test\" }"
"-DAPP_CLASSPATH={ \"testapp.jar\" }"
-otestapp.exe
java_all.c
Sadly, if I remove the references to __initenv, I get an executable, but
when I try to run it I get the following error (in a GUI dialog):
[TITLE: 16 bit MS-DOS Subsystem]
testapp.exe
The NTVDM CPU has encountered an illegal instruction.
CS:0e25 IP:010c OP:2e 63 00 88 13 Choose 'Close' to terminate the
application.
Thank you for your patience in reading this far!
 
 

Re:Unresolved external __declspec(dllimport), and illegal instruction

There are a couple of problems with this.
First is that you are posting a question about the command
line tools from C++ Builder version 5 in the newsgroup for
the old, 1997, Borland C++ compiler. You will generally
enjoy more useful responses to questions when they are
posted in an area whre people who use that product are
found. Try posting in one of the C++ Builder newsgroups,
groups with the word 'cppbuilder' in their name.
Quote
All of the unresolved reference errors went away,
with the exception of one referring to "___initenv",
which appears as follows in the source:

__declspec(dllimport) char **__initenv;
...
__initenv = _environ;
You do not show the text of the error. There are
several possible errors that could have been generated.
When you post over in the C++ Builder group, please
show the text of the error message.
The command line looks to be a problem. I do not know
if you will "get away" with it (the output shown does not
complain of it).
Quote
bcc32 -5 -tW -DJAVAW -DWIN32
"-IC:\Program Files\Borland\bcc55\Include"
"-IC:\Program Files\Java\j2sdk1.4.2_03\include"
"-DJAVA_ARGS={ \"heysen.common.ui.UiDialog_Test\" }"
"-DAPP_CLASSPATH={ \"testapp.jar\" }"
The quotes should encase the argument of the -I option
and not the whole item. The quotes are to identify the
space in the Program Files directory name as being part
of the name and not a delimiter. The items should be
something like this:
-I"C:\Program Files\Borland\bcc55\Include"
-I"C:\Program Files\Java\j2sdk1.4.2_03\include"
Note that the first of those duplicates what is
already established in the bcc32.cfg file that you
created when you installed the compiler. If you did
not create that file then refer to the compiler's
readme.txt file and create it and the ilink32.cfg
files.
The JAVA_ARGS and APP_CLASSPATH entries look questionable
but I do not know offhand what to suggest in the way of
altering them.
. Ed
Quote
MikL wrote:

I've never used C/C++ to write a Windows app (only
console apps), and I'm>hitting an error that suggests
I'm ignorantly misusing the Bcc32 compiler ("Borland
C++ 5.5 for Win32" with "Turbo Incremental Link 5.00")
under WinXP.

In case it's relevant, I'm attempting to compile the
Sun Java launcher (java.c + java_md.c). I've been
getting many "unresolved references" where java_md.c
calls functions in java.c, despite the presence of
good-looking function prototypes. To try to track
down the problem, I merged the source code from both
files into a single source file and compiled that.
All of the unresolved reference errors went away,
with the exception of one referring to "___initenv",
which appears as follows in the source:

__declspec(dllimport) char **__initenv;

int WINAPI WinMain(HINSTANCE inst, HINSTANCE
previnst, LPSTR cmdline, int cmdshow)
{
int ret;
SetThreadLocale(GetSystemDefaultLCID());
__initenv = _environ;
ret = main(__argc, __argv);
return ret;
}

What do I need to do? I've been Googling, and seen
a few references to IMPLIB and COFF2OMF, but I've done
my head in trying to understand what they're used for
and how to use them...and I don't know if they're related
to my problem anyway :( I've never even built a DLL.

The compile command I'm using is as follows. I've
broken it into multiple lines here for readability:

bcc32 -5 -tW -DJAVAW -DWIN32
"-IC:\Program Files\Borland\bcc55\Include"
"-IC:\Program Files\Java\j2sdk1.4.2_03\include"
"-IC:\Program Files\Java\j2sdk1.4.2_03\include\win32"
"-LC:\Program Files\Borland\bcc55\Lib"
-DJDK_MAJOR_VERSION=\"1\"
-DJDK_MINOR_VERSION=\"4\"
"-DJAVA_ARGS={ \"heysen.common.ui.UiDialog_Test\" }"
"-DAPP_CLASSPATH={ \"testapp.jar\" }"
-otestapp.exe
java_all.c

Sadly, if I remove the references to __initenv, I get
an executable, but when I try to run it I get the
following error (in a GUI dialog):

[TITLE: 16 bit MS-DOS Subsystem]
testapp.exe
The NTVDM CPU has encountered an illegal instruction.
CS:0e25 IP:010c OP:2e 63 00 88 13 Choose 'Close' to
terminate the application.

Thank you for your patience in reading this far!
 

Re:Unresolved external __declspec(dllimport), and illegal instruction

Ed Mulroy [TeamB] wrote:
Quote
First is that you are posting a question about the command
line tools from C++ Builder version 5 in the newsgroup for
the old, 1997, Borland C++ compiler.

>
>[TITLE: 16 bit MS-DOS Subsystem]
In conjuction with Ed's reply, you should not be trying to use 16bit
code modules with programs created by 5.5 as it only produces 32bit
code, which is incompatable with 16bit code without advanced
programming.
If you don't want to, or can't re-write the code for Win32, then
perhaps dropping back to BC++5.02 and compiling as DOS or Win16 would
work.
 

{smallsort}

Re:Unresolved external __declspec(dllimport), and illegal instruction

: 16 bit MS-DOS Subsystem]
Quote

In conjuction with Ed's reply, you should not be trying to use 16bit
code modules with programs created by 5.5 as it only produces 32bit
code, which is incompatable with 16bit code without advanced
programming.

If you don't want to, or can't re-write the code for Win32, then
perhaps dropping back to BC++5.02 and compiling as DOS or Win16 would
work.
This is _the_ standard Java 1.4 launcher C program source code from Sun
Microsystems, and it's used daily on millions of PCs, so I don't think I'll
rewrite it :)
I guess I'll just have to hunt down whatever secret module/library it is
that contains __initenv and look for an alternative.
 

Re:Unresolved external __declspec(dllimport), and illegal instruction

"Ed Mulroy [TeamB]" < XXXX@XXXXX.COM >wrote in message
Quote

There are a couple of problems with this.

First is that you are posting a question about the command
line tools from C++ Builder version 5 in the newsgroup for
the old, 1997, Borland C++ compiler. You will generally
enjoy more useful responses to questions when they are
posted in an area whre people who use that product are
found. Try posting in one of the C++ Builder newsgroups,
groups with the word 'cppbuilder' in their name.

Sorry to waste your bandwidth. It's a bit confusing when BCC32 calls itself
"Borland C++" and this NG is called "....borlandcpp".
The command line is a feature of how Sun likes to compile the code. The
quoting is bizarre but appears to work, from my inspection of the
preprocessor output. From my observations where the quotes start in an
argument is irrelevant as long as the spaces are within the quotes.
 

Re:Unresolved external __declspec(dllimport), and illegal instruction

Apology accepted.
And he's right, the quotes should probably encase just the path
and not the entire argument, I've never seen anyone write it that way
and know for a fact my IDE-generated makefiles for either
Borland C++ 5.02 or Borland C++Builder aren't written that way.
I think we know how many people use Sun's Java compiler,
they basically own Java. Have you read the instructions for
compiling this tool you're building (as in creating the resulting
executable :p)?
The reason you need to post in correct newsgroup is because the clutter
disorganized posts can grow quite disturbing.
"MikL" < XXXX@XXXXX.COM >wrote in message
Quote

"Ed Mulroy [TeamB]" < XXXX@XXXXX.COM >wrote in message
news:419b6d89$ XXXX@XXXXX.COM ...
>
>There are a couple of problems with this.
>
>First is that you are posting a question about the command
>line tools from C++ Builder version 5 in the newsgroup for
>the old, 1997, Borland C++ compiler. You will generally
>enjoy more useful responses to questions when they are
>posted in an area whre people who use that product are
>found. Try posting in one of the C++ Builder newsgroups,
>groups with the word 'cppbuilder' in their name.
>

Sorry to waste your bandwidth. It's a bit confusing when BCC32 calls
itself
"Borland C++" and this NG is called "....borlandcpp".

The command line is a feature of how Sun likes to compile the code. The
quoting is bizarre but appears to work, from my inspection of the
preprocessor output. From my observations where the quotes start in an
argument is irrelevant as long as the spaces are within the quotes.