NO

Author Topic: Compiling error for x64 Multithreaded DLL  (Read 12884 times)

cprog123

  • Guest
Compiling error for x64 Multithreaded DLL
« on: May 21, 2012, 04:13:01 AM »
I'm learning to use Pelles C 7.00 RC2 and also, learning my way around C and Windows programming. I have the following code.

Code: [Select]
#include <windows.h>

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
MessageBox(NULL, "This is a test", "Message", MB_OK);

return 0;
}

It compiles fine as a Single-threaded LIB and Multithreaded LIB, but it comes up with errors when trying to compile as a Multithreaded DLL. Here are the errors.

Code: [Select]
Building main.obj.
Building prog_1.exe.
POLINK: error: Unresolved external symbol '__C_specific_handler'.
POLINK: fatal error: 1 unresolved external(s).
*** Error code: 1 ***
Done.

What can I do, and how can I better understand this error. Usually I understand that when there is an unresolved external symbol, I am not linking a necessary library, but I'm not sure what to do about this. It is an x64 application.

An extra question if someone knows this. Looking at MSDN (microsoft network) there is a note that the Win32 api adapts to 64 bit compiling. In the above program, this means I simply compile to x64 and I have a 64bit program. Nothing else is necessary as far as coding is concerned, right?

CommonTater

  • Guest
Re: Compiling error for x64 Multithreaded DLL
« Reply #1 on: May 21, 2012, 07:39:40 AM »
If you are referring to the "run time library" setting on the compiler tab, you do need to link to the .lib file for the runtime DLL are using... and your software needs access to the DLL with the library in it at run time.

Assuming you want to use the Pelles C, runtime, you would need to link with pocrt64.lib and make the pocrt64.dll available to your program (usually just put a copy in your project directory). 

The difference is that when you use the single or multithreaded libs, the run time functions are linked right into your program, but when you use multithreaded DLL option the runtime functions are in a separate file that needs to be present so it can be loaded when the program starts. 

Depending who you ask, it is better to use the DLL version of things because that would permit updates to the CRT without having to recompile your program or, if you ask me, it's better to have the whole thing linked into one file to minimize the risk of the two being separated. 

Pelles C takes care of the 32 vs 64 bit libs thing for you when you set your project options.  (Check the Folders in your project options, you'll see.) Remember, the libs and headers orignate from microsoft but the ones included with Pelles C are tailored for use with Pelle's tool chain.
 
As for special considerations in 64 bit programming, you should probably read --> THIS <-- before you get too far into it.  There's not a lot of adaptation but what there is is absolutely necessary.
 
 

Offline TimoVJL

  • Global Moderator
  • Member
  • *****
  • Posts: 2091
Re: Compiling error for x64 Multithreaded DLL
« Reply #2 on: May 21, 2012, 01:25:14 PM »
__C_specific_handler seems to be missing from pocrt64.lib.
In crtmt64.lib it is in _ehandler.obj.
Maybe this is a bug.

May the source be with you

CommonTater

  • Guest
Re: Compiling error for x64 Multithreaded DLL
« Reply #3 on: May 21, 2012, 03:44:09 PM »
__C_specific_handler seems to be missing from pocrt64.lib.
In crtmt64.lib it is in _ehandler.obj.
Maybe this is a bug.

It could be. 

I don't do the multithreaded DLL thing with my code so I would be the last one to find it. :D


cprog123

  • Guest
Re: Compiling error for x64 Multithreaded DLL
« Reply #4 on: May 21, 2012, 06:46:31 PM »
I tried Pelles C 6.00 and it has the same error for an x64 program. x86 works fine.

Before I manually move files around since I will certainly go through the posted help, should I consider that this is an IDE configuration bug? or should it be obvious, that I have to manually move the DLL and link the files myself?

CommonTater

  • Guest
Re: Compiling error for x64 Multithreaded DLL
« Reply #5 on: May 21, 2012, 07:01:16 PM »
First don't move the DLL... make a copy of it.  (move and copy are very different things)

It won't be an IDE configuration bug in this case... it will most likely be an error in the DLL or LIB.

Yes you need to add pocrt64.lib to your linker options.  And a copy of the DLL should be in your project directory.




cprog123

  • Guest
Re: Compiling error for x64 Multithreaded DLL
« Reply #6 on: May 21, 2012, 07:11:36 PM »
Ok, I tried pocrt64.lib but it does not work.

crtmt64.lib works fine.

Since all the libs are in the same directory. Is crtmt64.lib Microsoft? or Pelles specific?

Offline TimoVJL

  • Global Moderator
  • Member
  • *****
  • Posts: 2091
Re: Compiling error for x64 Multithreaded DLL
« Reply #7 on: May 21, 2012, 07:13:54 PM »
Yes you need to add pocrt64.lib to your linker options.
No you don't have to do that, pocc.exe commandline option -MD insert directive '-defaultlib:pocrt' or '-defaultlib:pocrt64' to object file.
Quote
Is crtmt64.lib Microsoft? or Pelles specific?
PellesC
« Last Edit: May 21, 2012, 07:18:06 PM by timovjl »
May the source be with you

cprog123

  • Guest
Re: Compiling error for x64 Multithreaded DLL
« Reply #8 on: May 21, 2012, 07:26:24 PM »
Ok, I got a little confused here with the last comment. I'll try to explain what I did.

I added pocrt64.lib to the list of libraries to link against in the linker options. It did not work.

So instead of pocrt64.lib I tried linking crtmt64.lib. That did work.

So now I'm confused. What works and what does not? and what DLL am I making use of after this is built.

Offline Stefan Pendl

  • Global Moderator
  • Member
  • *****
  • Posts: 582
    • Homepage
Re: Compiling error for x64 Multithreaded DLL
« Reply #9 on: May 21, 2012, 09:15:39 PM »
Are you sure you want to use the WinMain function for a DLL?

A DLL usually uses a DllMain function, if I am not mistaken.

Sure this can all be changed through the project properties, but I would still use the expected main function for the resulting executable.

You can use preprocessor directives to accomplish this.
---
Stefan

Proud member of the UltraDefrag Development Team

CommonTater

  • Guest
Re: Compiling error for x64 Multithreaded DLL
« Reply #10 on: May 21, 2012, 10:35:53 PM »
Guys ... I think we're getting rather confused here...

The OP is talking about the RunTime Library options in the Compiler tab of his project.

I don't get the impression he's trying to write a DLL...


Offline Stefan Pendl

  • Global Moderator
  • Member
  • *****
  • Posts: 582
    • Homepage
Re: Compiling error for x64 Multithreaded DLL
« Reply #11 on: May 21, 2012, 10:58:57 PM »
Code: [Select]
#include <windows.h>

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
MessageBox(NULL, "This is a test", "Message", MB_OK);

return 0;
}

It compiles fine as a Single-threaded LIB and Multithreaded LIB, but it comes up with errors when trying to compile as a Multithreaded DLL. Here are the errors.
As it looks for me he is using the above code for static and dynamic libraries.
Is this supposed to work at all?

main, WinMain and DllMain do have a special purpose in the Windows world as far as I know.

We don't know the project properties, nor do we have an example project at hand, so it is all just guessing ;)
---
Stefan

Proud member of the UltraDefrag Development Team

CommonTater

  • Guest
Re: Compiling error for x64 Multithreaded DLL
« Reply #12 on: May 22, 2012, 03:06:53 AM »
We don't know the project properties, nor do we have an example project at hand, so it is all just guessing ;)

I agree, we do need clarification, particularly since he may have found a bug in the libraries...

CProg... Are you talking about the setting circled in red in the image below...

Also if you go into your Project menu you will see the option to zip up your files.  Do this and attach them to your message so we can have a look...

Thank you.


cprog123

  • Guest
Re: Compiling error for x64 Multithreaded DLL
« Reply #13 on: May 23, 2012, 05:24:36 AM »
Sorry it took me this long to answer.

Yes, the red circled image. I set that to Multithreaded (DLL). I will zip up the project and post it just a little later. Give me about an hour or two - sorry for the delay.

cprog123

  • Guest
Re: Compiling error for x64 Multithreaded DLL
« Reply #14 on: May 23, 2012, 05:34:35 AM »
Ok, I reset the project. To make sure there is no confusion. I created a new project, added main.c and the code I posted at the beginning of this thread, then I changed to Multithreaded (DLL) and tried to build. I did not add any link objects this time around, so you guys can take a look for yourself.

Don't forget, adding crtmt64.lib as a linked library works, but adding pocrt64.lib does not. I think we are trying to figure out why pocrt64.lib does not work correctly when setting to Multithreaded (DLL).

I will wait for your examinations. Here is the project, as explained.