Pelles C forum

C language => Beginner questions => Topic started by: WRP on June 12, 2014, 11:00:10 PM

Title: Trouble linking C runtime
Post by: WRP on June 12, 2014, 11:00:10 PM
I have a small program that links to a library statically (.lib) or dynamically (.dll). It compiles with the Tiny C compiler, but fails with PellesC. With static linking, the error is "can't find LIBC.lib", and with dynamic linking it is "can't find MSVCRT.lib".

I tried renaming crt.lib to msvcrt.lib. I also tried using POLIB to make a msvcrt.lib from my system's msvcrt.dll. In both cases, I got the error:

POLINK: error: Unresolved external symbol '__imp____p___argv'.
POLINK: error: Unresolved external symbol '__imp____p___argc'.

What is the problem and what can I do to compile the program?
Title: Re: Trouble linking C runtime
Post by: frankie on June 13, 2014, 10:14:35 AM
Try using the switch '-Gn' undecorate imported stdcall.
the '__imp__' prefix means that the function is declared as imported from DLL (in the .h file there is something like '__declspec(dllimport) _p__argv).
To solve the problem you need to know what is the calling convention, and what is the real name in the DLL (decorated or not).
The request for MSVCRT.lib means that the library you want to use has been linked against the Microsoft runtime. Renaming the PellesC runtime could be the real cause of your problem if the missing symbols come from MSVCRT.lib (and not available in pocrt.lib).
The best solution is to get a copy of MSVCRT.lib (which is widly available and come also with free compilers and SDK from MS), select the switch '-Zl' in the compiler tab to omit default libraries, and add MSVCRT.lib in the linker tab.
Title: Re: Trouble linking C runtime
Post by: WRP on June 14, 2014, 08:56:33 PM
Try using the switch '-Gn' undecorate imported stdcall.

OK, tried that but it had no effect.

I tried -Zl "Omit default library name in object files" but then got error:
POLINK: error: Unresolved external symbol '__WinMainCRTStartup'.

Quote
The best solution is to get a copy of MSVCRT.lib..., select the switch '-Zl' in the compiler tab to omit default libraries, and add MSVCRT.lib in the linker tab.

I added a msvcrt.lib to \Lib and then got errors:
POLINK: error: Symbol '___argv' is multiply defined: 'crt.lib(_crt0dat.obj)' and 'msvcrt.lib(msvcrt.dll)'.
POLINK: error: Symbol '___argc' is multiply defined: 'crt.lib(_crt0dat.obj)' and 'msvcrt.lib(msvcrt.dll)'.

Then I removed crt.lib and got error:
POLINK: fatal error: File not found: 'crt.lib'.

It seems that Pelles C links to its own version of the C lib and can't use DLLs that are linked to msvc.lib because they conflict. Is it then impossible to use DLLs from other compilers?
Title: Re: Trouble linking C runtime
Post by: frankie on June 14, 2014, 10:22:20 PM
I added a msvcrt.lib to \Lib and then got errors:
POLINK: error: Symbol '___argv' is multiply defined: 'crt.lib(_crt0dat.obj)' and 'msvcrt.lib(msvcrt.dll)'.
POLINK: error: Symbol '___argc' is multiply defined: 'crt.lib(_crt0dat.obj)' and 'msvcrt.lib(msvcrt.dll)'.
That's OK
Then I removed crt.lib and got error:
POLINK: fatal error: File not found: 'crt.lib'.

It seems that Pelles C links to its own version of the C lib and can't use DLLs that are linked to msvc.lib because they conflict. Is it then impossible to use DLLs from other compilers?
Have you compiled your sources with the switch '-Zl' in the compiler tab to omit default libraries before linking?

Could you post a simple project, with possibly a small library from TinyC to check?
Title: Re: Trouble linking C runtime
Post by: WRP on June 15, 2014, 03:07:19 AM
Have you compiled your sources with the switch '-Zl' in the compiler tab to omit default libraries before linking?
Yes, I always get:
POLINK: error: Unresolved external symbol '__WinMainCRTStartup'.

Here is a small project and the binary compiled with TCC.
Title: Re: Trouble linking C runtime
Post by: frankie on June 15, 2014, 06:19:49 PM
The library is a GUI library, so you have to setup a windows subsystem project.
The uipstub library provides for the missing entry point WinMan.
The library use __cdecl convention (see the use of the new pragma default_convention of PellesC V8 before inclusion of 'iup.h').
I created the project using standard PellesC runtime (not msvcrt).

Anyway, unless you are interested to linking with TinyC prebuild libraries, I suggest you to download the iup sources and natively compile them in PellesC.  ;)
Title: Re: Trouble linking C runtime
Post by: WRP on June 15, 2014, 11:37:58 PM
As far as I can tell, I did the same thing as you. I created a Windows EXE project in the IDE. Here is my project file.

Code: [Select]
#
# PROJECT FILE generated by "Pelles C for Windows, version 8.00".
# WARNING! DO NOT EDIT THIS FILE.
#

POC_PROJECT_VERSION = 7.00#
POC_PROJECT_TYPE = 0#
POC_PROJECT_OUTPUTDIR = output#
POC_PROJECT_RESULTDIR = .#
POC_PROJECT_ARGUMENTS = #
POC_PROJECT_WORKPATH = #
POC_PROJECT_EXECUTOR = #
POC_PROJECT_ZIPEXTRA = #
CC = pocc.exe#
AS = poasm.exe#
RC = porc.exe#
LINK = polink.exe#
SIGN = posign.exe#
CCFLAGS = -std:C99 -Tx86-coff -Ot -Ob1 -fp:precise -W1 -Gd#
ASFLAGS = -AIA32 -Gz#
RCFLAGS = #
LINKFLAGS = -subsystem:windows -machine:x86 kernel32.lib user32.lib gdi32.lib comctl32.lib comdlg32.lib advapi32.lib delayimp.lib iup.lib iupstub.lib -delayload:iup.dll#
SIGNFLAGS = -location:CU -store:MY -timeurl:http://timestamp.verisign.com/scripts/timstamp.dll -errkill#
INCLUDE = $(PellesCDir)\Include\Win;$(PellesCDir)\Include;..\..\iup-3.10.1_Win32_dll10_lib\include#
LIB = $(PellesCDir)\Lib\Win;$(PellesCDir)\Lib;..\..\iup-3.10.1_Win32_dll10_lib#

#
# Build alarm.exe.
#
alarm.exe: \
output\alarm.obj \
output\iup.res
$(LINK) $(LINKFLAGS) -out:"$@" $**

#
# Build alarm.obj.
#
output\alarm.obj: \
..\..\iup-3.10.1_Examples\C\alarm.c \
..\..\iup-3.10.1_Win32_dll10_lib\include\iup.h \
..\..\iup-3.10.1_Win32_dll10_lib\include\iupdef.h \
..\..\iup-3.10.1_Win32_dll10_lib\include\iupkey.h
$(CC) $(CCFLAGS) "$!" -Fo"$@"

#
# Build iup.res.
#
output\iup.res: \
..\..\iup-3.10.1_Win32_vc12_lib\etc\iup.rc \
..\..\iup-3.10.1_Win32_vc12_lib\etc\iup.manifest \
..\..\iup-3.10.1_Win32_vc12_lib\etc\pen.cur \
..\..\iup-3.10.1_Win32_vc12_lib\etc\tecgraf.ico
$(RC) $(RCFLAGS) "$!" -Fo"$@"

.EXCLUDEDFILES:

.SILENT:

I also tried using just the files you returned to compile the project.

With just the files that come with Pelles C, I got the error:
POLINK: fatal error: File not found: 'MSVCRT.lib'.

When I added msvcrt.lib to PellesC\Lib, I got:
POLINK: error: Symbol '___argv' is multiply defined: 'crt.lib(_crt0dat.obj)' and 'msvcrt.lib(msvcrt.dll)'.
POLINK: error: Symbol '___argc' is multiply defined: 'crt.lib(_crt0dat.obj)' and 'msvcrt.lib(msvcrt.dll)'.

What did you do to make it compile?
Title: Re: Trouble linking C runtime
Post by: frankie on June 16, 2014, 09:16:54 AM
Probably you doesn't move to -subsystem:windows? (see below)
Anyway you can look the project options to check compiler and linker switches used.

No. It's not black magic ...  ;)
Title: Re: Trouble linking C runtime
Post by: WRP on June 17, 2014, 01:45:22 AM
I discovered the linker option -force:multiple. It is not displayed in the IDE controls. This causes the linker to ignore when symbols are multiply defined. Now it will build and I get a working executable.

I don't know how safe this strategy is, though.
Title: Re: Trouble linking C runtime
Post by: frankie on June 17, 2014, 08:53:46 AM
WRP, sorry, but I have not understood if my project worked for you.
My project, with msvcrt.lib in libraries folder, compiles or not? And if not which errors you still have? The same as before?

EDIT: Maybe I found the problem. Why you linked with delay load the library iup.lib? It's a nosense. the iup code in iup.lib is the first to execute, and that code calls your main routine. Why you added iup.dll as delay load?

P.S. Using -force:multiple is not a good option. Some symbols maybe dynamically allocated and calling them in the wrong place (the first definition that linker can find) could lead to many many problems...
Title: Re: Trouble linking C runtime
Post by: WRP on June 17, 2014, 06:41:10 PM
My project, with msvcrt.lib in libraries folder, compiles or not? And if not which errors you still have? The same as before?
I tried your project. The errors are the same.

Quote
Why you added iup.dll as delay load?
I just tried it to see what would happen. I noticed no difference.
Title: Re: Trouble linking C runtime
Post by: frankie on June 18, 2014, 09:06:21 AM
My project, with msvcrt.lib in libraries folder, compiles or not? And if not which errors you still have? The same as before?
I tried your project. The errors are the same.

Strange.   :P
It seems that on your system the linker includes immediatly the pocrt.lib, then when the iup.lib is linked it includes msvcrt.lib and found the duplicate symbols.
What is strange is that using my project and a standard PellesC installation you still get different result. Or you have made modifications, or added other objects or libraries?  :(
The only solution is to force the linker to load the msvcrt.lib before anything else.
This can be done inserting msvcrt.lib as first library on the linker command line or in the IDE's libraries list (in the linker tab, see image).
The sequence of objects and libraries linked is very important.
Eventually use also the switch -Zl to omit the default libraries in object files.
Title: Re: Trouble linking C runtime
Post by: WRP on June 18, 2014, 10:16:13 PM
It is a default installation, no changes.

I put msvcrt.lib as first library in the linker list and still get error:
POLINK: error: Symbol '___argv' is multiply defined: 'crt.lib(_crt0dat.obj)' and 'msvcrt.lib(msvcrt.dll)'.
POLINK: error: Symbol '___argc' is multiply defined: 'crt.lib(_crt0dat.obj)' and 'msvcrt.lib(msvcrt.dll)'.

Then I added switch -Zl to omit the default libraries in object files and got error:
POLINK: error: Unresolved external symbol '__WinMainCRTStartup'.

Did it actually work on your system?
Title: Re: Trouble linking C runtime
Post by: frankie on June 19, 2014, 09:18:19 AM
Did it actually work on your system?
On my system it compiles, links and run like a charm... (see picture)

It is a default installation, no changes. The msvcrt.lib I use is the 100 that loads MSVCR100.dll in runtime.

I put msvcrt.lib as first library in the linker list and still get error:
POLINK: error: Symbol '___argv' is multiply defined: 'crt.lib(_crt0dat.obj)' and 'msvcrt.lib(msvcrt.dll)'.
POLINK: error: Symbol '___argc' is multiply defined: 'crt.lib(_crt0dat.obj)' and 'msvcrt.lib(msvcrt.dll)'.

Then I added switch -Zl to omit the default libraries in object files and got error:
POLINK: error: Unresolved external symbol '__WinMainCRTStartup'.
Your problem is clearly due to the fact that the linker use both msvcrt and pocrt libraries together in the first case so you get the multiple definition.
In the second case, omitting the default libraries, pocrt is not loaded anymore, but somewhere you reference the symbol '__WinMainCRTStartup' that is in no library.
Really strange, difficult to say what is the problem.
The cause of the problem could be so subtle that is very difficult to identify.
I asked you to use the project that I published, unzip it in a folder, double click the 'Alarm.prj' in that directory then compile and run it as is. I'm not sure that you have done so, if you still just look the configuration of my project and try to adapt yours, maybe we'll never solve the problem. This because if in your project there are other switch set or missing, or it includes other modules or libraries compiled differently I can't test and nor even know.
If you have used *just* my project maybe the msvcrt.lib is not correct. Download a version 100 or newer.
I attach also a simplified version that is just a windows compile and doesn't use iupstub.lib.

If someone eslse want compile the sample is welcome.
Title: Re: Trouble linking C runtime
Post by: frankie on June 19, 2014, 10:55:02 AM
This is the msvcrt.lib created using polib against msvcr100.dll.
Title: Re: Trouble linking C runtime
Post by: aMarCruz on June 19, 2014, 07:49:09 PM
WRP,
try this:

In menu [Project->Project Options...]
Compiler tab: check 'Omit default library name in object files' (commandline /Zl).
Linker tab: add "msvcrt.lib crt.lib", in this order.

Copy msvcrt.lib to any folder (ex. C:\Dev\Lib) and add this location to Pelles Lib folders.

This is working for me with msvcrt 7.1 (I need this 'cause I'm linkink with winapims.lib to make FLL modules for VFP 9.0, and winapims depends on ms 7.1 runtime).

---edit
Ignore the warning
POLINK: warning: Multiple '.rdata' sections found with different flags (0x40000040 and 0xc0000040).

@beto
Title: Re: Trouble linking C runtime
Post by: WRP on June 20, 2014, 04:02:52 AM
In menu [Project->Project Options...]
Compiler tab: check 'Omit default library name in object files' (commandline /Zl).
Linker tab: add "msvcrt.lib crt.lib", in this order.
Thanks, I gave this a try. Checking /Zl gives

POLINK: error: Unresolved external symbol '__WinMainCRTStartup'.

then adding msvcrt.lib & crt.lib goes back to

POLINK: error: Unresolved external symbol '__imp____argv'.
POLINK: error: Unresolved external symbol '__imp____argc'.
Title: Re: Trouble linking C runtime
Post by: WRP on June 20, 2014, 04:08:14 AM
Here are the results with PellesC v8rc4 32-bit on Windows 7 64-bit. I built your Alarm and Alarm-nomain projects with 5 different versions of MSVCRT placed in C:\Program Files (x860\PellesC\Lib.

Versions of MSVCRT:
1. Made by POLIB from msvcrt.dll
2. Made by POLIB form msvcr100.dll
3. Taken from Windows Driver Kit
4. Taken from Visual C++ 2010
5. Made by tiny_impdef from Tiny C compiler's msvcrt.def

-------------------------------------------------
Building Alarm-nomain
1. msvcrt.lib by POLIB from msvcrt.dll worked
2. msvcrt.lib by POLIB from msvcr100.dll worked
3. msvcrt.lib from WDK worked
4. msvcrt.lib from VS2010 worked

5. msvcrt.lib from TCC gave error:
POLINK: error: Symbol '___argc' is multiply defined: 'msvcrt.lib(msvcrt.dll)' and 'crtmt.lib(_crt0dat.obj)'.
POLINK: error: Symbol '___argv' is multiply defined: 'msvcrt.lib(msvcrt.dll)' and 'crtmt.lib(_crt0dat.obj)'.

If I set -Zl "Omit default library name".

1. msvcrt.lib by POLIB from msvcrt.dll:
2. msvcrt.lib by POLIB from msvcr100.dll:
POLINK: error: Unresolved external symbol '___argv'.
POLINK: error: Unresolved external symbol '___argc'.
POLINK: error: Unresolved external symbol '__WinMainCRTStartup'.

3. msvcrt.lib from WDK:
4. msvcrt.lib from VS2010:
POLINK: error: Unresolved external symbol '___argv'.
POLINK: error: Unresolved external symbol '___argc'.

5. msvcrt.lib from TCC:
POLINK: error: Unresolved external symbol '__WinMainCRTStartup'.

-------------------------------------------------
Building Alarm
1. msvcrt.lib by POLIB from msvcrt.dll:
2. msvcrt.lib by POLIB from msvcr100.dll:
POLINK: error: Unresolved external symbol '__imp____argv'.
POLINK: error: Unresolved external symbol '__imp____argc'.

3. msvcrt.lib from WDK: worked
4. msvcrt.lib from VS2010: worked

5. msvcrt.lib from TCC:
POLINK: error: Symbol '___argc' is multiply defined: 'msvcrt.lib(msvcrt.dll)' and 'crtmt.lib(_crt0dat.obj)'.
POLINK: error: Symbol '___argv' is multiply defined: 'msvcrt.lib(msvcrt.dll)' and 'crtmt.lib(_crt0dat.obj)'.

If I set -Zl "Omit default library name".

All:
POLINK: error: Unresolved external symbol '__WinMainCRTStartup'.

-------------------------------------------------
So, for dynamic binding, I can use the libs from WDK and Visual Studio. I would still like to know, however, why the libs made by POLIB don't work for me, and why TCC's lib doesn't work with PellesC.
Title: Re: Trouble linking C runtime
Post by: frankie on June 20, 2014, 12:01:52 PM
Ok I found the problem.
I reproduced the errors (I have update libraries and header from MS so I could always link).
The only problem is the library iupstub.lib that would link with static variables __argc and __argv.
An executable have always to link with a static library containing the entry point (entry point can't be in a DLL which is still not loaded) and uses pocrt.lib for PellesC and libcmt.lib for MS. The two variables __argc and __argv are statically defined in both libraries, so could not be linked together.
Now happen that msvcrt.lib refers to libcmt.lib so automatically include it in the linkage, while the compiler itself includes pocrt.lib as default library. This lead to the multiply defined symbols error.
Using the switch -Zl omits all libraries so the entry point __WinMainCRTStartup is missing.
Adding libcmt.lib to the linker libraries works only using multithreaded DLL.

The best solution is to recompile in pellesC the iupstub.lib and go on.
With a native iupstub.lib you can compile with single threaded and multithreaded static and dynamic libraries with no errors, but compiling in singlethreaded is wrong anyway because the iup library and DLL are created as multithreaded.
Moreover using native iupstub.lib you don't need anymore to specify msvcrt.lib in the linker.  ;)
I have attached a workspace including the fixed alarm project and the iupstub.lib native.  8)
Title: Re: Trouble linking C runtime
Post by: WRP on June 20, 2014, 09:59:56 PM
I will give it a try with the iupstub.lib native.

Since dynamic linking worked with the msvcrt.lib from VC++ 2010, I decided to try static linking with the libcmt.lib. Linking with the static version of iup.lib doesn't require iupstub.lib, so I expected to have no problem, but I got these errors. I'm really confused by the conflict of libcmt.lib with itself.

Code: [Select]
POLINK: error: Symbol 'jnedef' is multiply defined: 'libcmt.lib(_cos_.obj)' and 'libcmt.lib(_cos_.obj)'.
POLINK: error: Symbol 'jnedef' is multiply defined: 'libcmt.lib(_sin_.obj)' and 'libcmt.lib(_sin_.obj)'.
POLINK: error: Symbol 'restore_CW' is multiply defined: 'libcmt.lib(_common_.obj)' and 'libcmt.lib(_common_.obj)'.
POLINK: error: Symbol 'CW_is_restored' is multiply defined: 'libcmt.lib(_common_.obj)' and 'libcmt.lib(_common_.obj)'.
POLINK: error: Symbol 'cwdefault' is multiply defined: 'libcmt.lib(_87disp_.obj)' and 'libcmt.lib(_87disp_.obj)'.
POLINK: error: Symbol 'setcw' is multiply defined: 'libcmt.lib(_87disp_.obj)' and 'libcmt.lib(_87disp_.obj)'.
POLINK: error: Symbol '___argc' is multiply defined: 'crt.lib(_crt0dat.obj)' and 'libcmt.lib(crt0dat.obj)'.
POLINK: error: Symbol '___argv' is multiply defined: 'crt.lib(_crt0dat.obj)' and 'libcmt.lib(crt0dat.obj)'.
POLINK: error: Symbol '___wargv' is multiply defined: 'crt.lib(_crt0dat.obj)' and 'libcmt.lib(crt0dat.obj)'.
POLINK: error: Symbol '_exit' is multiply defined: 'crt.lib(exit.obj)' and 'libcmt.lib(crt0dat.obj)'.
POLINK: error: Symbol '_localeconv' is multiply defined: 'crt.lib(localeconv.obj)' and 'libcmt.lib(lconv.obj)'.
POLINK: error: Symbol '_signal' is multiply defined: 'crt.lib(signal.obj)' and 'libcmt.lib(winsig.obj)'.
POLINK: error: Symbol '_raise' is multiply defined: 'crt.lib(raise.obj)' and 'libcmt.lib(winsig.obj)'.
POLINK: error: Symbol '___xi_a' is multiply defined: 'crt.lib(_initex.obj)' and 'libcmt.lib(crt0init.obj)'.
POLINK: error: Symbol '___xi_z' is multiply defined: 'crt.lib(_initex.obj)' and 'libcmt.lib(crt0init.obj)'.
POLINK: error: Symbol '___xt_a' is multiply defined: 'crt.lib(_initex.obj)' and 'libcmt.lib(crt0init.obj)'.
POLINK: error: Symbol '___xt_z' is multiply defined: 'crt.lib(_initex.obj)' and 'libcmt.lib(crt0init.obj)'.
POLINK: error: Symbol '__NLG_Dispatch' is multiply defined: 'crt.lib(seh1.obj)' and 'libcmt.lib(exsup.obj)'.
POLINK: error: Symbol '__NLG_Return2' is multiply defined: 'crt.lib(seh1.obj)' and 'libcmt.lib(exsup.obj)'.
POLINK: error: Symbol '__NLG_Destination' is multiply defined: 'crt.lib(seh1.obj)' and 'libcmt.lib(exsup.obj)'.
POLINK: error: Symbol '__global_unwind2' is multiply defined: 'crt.lib(seh1.obj)' and 'libcmt.lib(exsup.obj)'.
POLINK: error: Symbol '__local_unwind2' is multiply defined: 'crt.lib(seh1.obj)' and 'libcmt.lib(exsup.obj)'.
POLINK: error: Symbol '__abnormal_termination' is multiply defined: 'crt.lib(seh1.obj)' and 'libcmt.lib(exsup.obj)'.
POLINK: error: Symbol '__NLG_Notify1' is multiply defined: 'crt.lib(seh1.obj)' and 'libcmt.lib(exsup.obj)'.
POLINK: error: Symbol '__NLG_Notify' is multiply defined: 'crt.lib(seh1.obj)' and 'libcmt.lib(exsup.obj)'.

Title: Re: Trouble linking C runtime
Post by: frankie on June 20, 2014, 10:55:14 PM
Use -Zl switch and eventually include libcmt.lib from MS SDK (or WDDK).
In the compiler tab select multithreaded runtime.
I'm looking for a PellesC workspace to natively compile the iup library. When ready I'll publish it.
Title: Re: Trouble linking C runtime
Post by: WRP on June 21, 2014, 01:54:10 AM
In the IUP import libs, I replaced the iupstub.lib with your PellesC native version. Now the programs compile without any dependence on MSVCRT. Good work.

I tried static linking again with the -Zl switch and selected multithreaded runtime. (It doesn't seem to matter whether I explicitly include libcmt.lib.) Errors are now reduced to these few. If I set -force:multiple, then it will build and seems to work. I know that with static linking it is best to compile everything with the same compiler, but I'm curious about these errors. It seems that libcmt.lib is conflicting with itself.

Code: [Select]
POLINK: error: Symbol 'jnedef' is multiply defined: 'libcmt.lib(_cos_.obj)' and 'libcmt.lib(_cos_.obj)'.
POLINK: error: Symbol 'jnedef' is multiply defined: 'libcmt.lib(_sin_.obj)' and 'libcmt.lib(_sin_.obj)'.
POLINK: error: Symbol 'restore_CW' is multiply defined: 'libcmt.lib(_common_.obj)' and 'libcmt.lib(_common_.obj)'.
POLINK: error: Symbol 'CW_is_restored' is multiply defined: 'libcmt.lib(_common_.obj)' and 'libcmt.lib(_common_.obj)'.
POLINK: error: Symbol 'cwdefault' is multiply defined: 'libcmt.lib(_87disp_.obj)' and 'libcmt.lib(_87disp_.obj)'.
POLINK: error: Symbol 'setcw' is multiply defined: 'libcmt.lib(_87disp_.obj)' and 'libcmt.lib(_87disp_.obj)'.

The IUP libs are a lot of work to build. A PellesC workspace would be a big convenience.
Title: Re: Trouble linking C runtime
Post by: frankie on June 21, 2014, 04:58:06 PM
In the IUP import libs, I replaced the iupstub.lib with your PellesC native version. Now the programs compile without any dependence on MSVCRT. Good work.
Thanks  8)
The use of static variables, as __argc and __argv, from msvcrt.dll is rare, but it's a problem when linking with a different compiler. But fortunatelyit is used only in iupstub.lib, so recompiling just that library made the job. Anyway I expect that the values of iupstub.lib, linked with pocrt.dll, and that inside the iup.dll, linked to msvcrt.dll, are different (the pointers should be different).
I tried static linking again with the -Zl switch and selected multithreaded runtime. (It doesn't seem to matter whether I explicitly include libcmt.lib.) Errors are now reduced to these few. If I set -force:multiple, then it will build and seems to work. I know that with static linking it is best to compile everything with the same compiler, but I'm curious about these errors. It seems that libcmt.lib is conflicting with itself.

Code: [Select]
POLINK: error: Symbol 'jnedef' is multiply defined: 'libcmt.lib(_cos_.obj)' and 'libcmt.lib(_cos_.obj)'.
POLINK: error: Symbol 'jnedef' is multiply defined: 'libcmt.lib(_sin_.obj)' and 'libcmt.lib(_sin_.obj)'.
POLINK: error: Symbol 'restore_CW' is multiply defined: 'libcmt.lib(_common_.obj)' and 'libcmt.lib(_common_.obj)'.
POLINK: error: Symbol 'CW_is_restored' is multiply defined: 'libcmt.lib(_common_.obj)' and 'libcmt.lib(_common_.obj)'.
POLINK: error: Symbol 'cwdefault' is multiply defined: 'libcmt.lib(_87disp_.obj)' and 'libcmt.lib(_87disp_.obj)'.
POLINK: error: Symbol 'setcw' is multiply defined: 'libcmt.lib(_87disp_.obj)' and 'libcmt.lib(_87disp_.obj)'.

The IUP libs are a lot of work to build. A PellesC workspace would be a big convenience.
This is surely due multiple inclusion of libcmt.lib. Maybe from more libs and runtime DLL's or libs load different versions of the same lib. in this case if the library is the same using -force:multiple should be acceptable.
As already said the best solution is to natively compile libraries. I have already compiled iup.dll and iup.lib. When I'll finish I'll post it.