Pelles C forum
C language => Expert questions => Topic started by: John Z on January 23, 2025, 09:30:35 PM
-
Hi,
I have four batch files to build a project 1 each for compile, res, and link, then a master batch file to call each file and pass in the required information. It all works wonderfully well from a command window. Creates the program just as the IDE does.
Being so successful compiling and creating the final exe I then added the master bat file to the tools in the IDE. Compile ran fine, the resource builder ran fine but the linker failed with the following message
POLINK: error: Unresolved external symbol '_WinMainCRTStartup' - referenced from '<common>'.
to restate the problem:
When I run the make_link.bat in a command window, not in the IDE, it runs fine creates the exe without any problems.
When I run the same make_link.bat from the IDE Tools menu, it fails for the error.
Searching C:\Program Files\PellesC_V12\Lib\Win64\shlwapi.lib
Searching C:\Program Files\PellesC_V12\Lib\Win64\uxtheme.lib
Searching C:\Program Files\PellesC_V12\Lib\Win64\dwmapi.lib
POLINK: error: Unresolved external symbol '_WinMainCRTStartup' - referenced from '<common>'.
POLINK: fatal error: 1 unresolved external(s).
From the command window running make_link.bat it finds crt64.lib -
Searching C:\Program Files\PellesC_V12\Lib\Win64\dwmapi.lib
Searching C:\Program Files\PellesC_V12\Lib\crt64.lib
From the IDE Tools it fails if the Tool directly executes make_link.bat and if the make_all.bat calls make_link.bat. From the command line it works both when executed directly or when executed by make_all.bat.
weird, strange, but not wonderful -
Thoughts?
John Z
-
Hi John,
Could you attach the zip file containing the project files?
-
Hi Vortex,
Can't do that there are over 40 C files and that is more than 2.3Meg, not counting .h files, resources like icons, bmp, and dll's, etc.
I will try the batch build on a smaller project and see if I get the same issue.
Thanks, should have done that first, but since it worked I was blinded :(
John Z
-
Hi John,
Even with a response file
For linking
Echo *********************
Echo *** Linking files ***
Echo *********************
"C:\Program Files\PellesC\Bin\polink.exe" @LinkRelease.cmf
[size=78%]POLINK has the following general syntax:[/size]
POLINK [ { filespec | @response-file | option } ... ]
The filespec argument specifies the name of a library (.lib or .a), a module-definition file (.def), a binary resource file (.res), or an object file (.obj or .o). Wildcards are allowed for all types except a module-definition file.
If you have many files or options - use a response file. It is a text file with the same format as the command line. Line feeds are treated as spaces. The name of the response file must be preceded by a @ character on the command line. The response file may use either OEM or UTF-16LE encoding (from version 5.0).
An option starts with the / (or -) character, may be given in upper or lower case, and can be one of the following:
I use this when MicroSoft Assembler was called "Masm", I was 30yo.... 35 yars ago I was young and nice... ::)
-
Hi HellOfMice,
Yes the exact same make_link.bat and the same exact response file.
Works when run in a command window, but does not work when called from the Tool menu.
The compile batch file and resources batch file both work in both cases.
Thanks,
John Z
-
COpy your batch file in another one
in the first CALL the second or make a COMMAND /C
-
That is the basic procedure that I do.
case #1 when running using make_all.bat
make_all.bat calls make_objs.bat, then calls make_res.bat, then calls make_link.bat.
case #2 I execute make_objs.bat directly, I execute make_res.bat directly, I execute make_link.bat directly
When doing this from a command windows both cases work perfectly.
When I do it from the IDE tools make_link.bat always fails with the aforementioned error when run itself, and when run by using make_all.bat from Tools.
John Z
-
Partial solution -
When run from the Pelles TOOL IDE the WHERE command is not recognized, when run from a command window it is....easy fix then more testing....
John Z
-
Just ECHO PATH, INCLUDE, LIB to see environment in both cases.
Useful Tool for poide
Command: C:\Windows\system32\cmd.exe
Arguments: /C SET
Also check Tools -> Options -> Folders -> Executables
-
Thanks TimoVJL.
It is fixed, builds both at the command line and from the IDE TOOL . The problem was entirely due to the WHERE command. Unfortunately while WHERE is very useful, it is not available when using the IDE for whatever reason. Needed 5 commands to replace what WHERE does in one command.
However it works now, but another limitation is imposed: no spaces in the object filenames.
I'll probably write a quick replacement for WHERE in C to restore the capability of WHERE.
John Z
:) :) :)
Got WHERE to work for both IDE and command line by using a separate cmd /c call for it. Yes all is right again. These 4 batch files make it very easy to build a program without extensive editing. When cleaned up I'll post in case anyone else wishes to make use of them. AFTER MORE TESTING of course.
-
copy the in a RAM drive under a name then compile in RAM drive
-
copy the in a RAM drive under a name then compile in RAM drive
What and why ???
Is this another one kind of "optimization" idea ?
-
Why not.
Our files are not very big
-
where.exe is located at Windows\system32 and Windows\SysWOW64 folders
so keeping cmd.exe PATH variable correct in poide too, less problems to solve ;)
-
RAM disks are useful tools but today's NVMe drivers are very fast.
-
Here is the batch build package - it has been tested on my largest program, the one mentioned previously.
It successfully builds from the IDE, or from a command window, the batch created final exe file
matched exactly the build by the IDE.
Change a few lines in make_all.bat, create baselink.lst (only 7 lines) and ready to build.
Limitations: All source files must be in the same directory for make_objs.bat. If multiple
directories are used clone make_objs.bat to make_objs1.bat 2.bat etc., and change
the source location in each. Then call each from the make_all.bat
Biggest thing is you must make the baselink.lst for the project manually
A general guide is in the 7z, and directions are also in each file as to what to change.
Hopefully useful, but if not its OK....
John Z
-
Thank You John
-
Biggest thing is you must make the baselink.lst for the project manually
Now you can make it easily with an Add-in.
Use Add-in BaseLink.dll
Purpose: Write a BaseLink.lst header file for the batch file Make_link.bat
Where: The BaseLink.lst file will be in the currently active project directory
What to do with it: Copy it to wherever the make_link.bat is for the given project being batch made
How: Copy dll to AddIns, restart Pelles load your project then
Run: Under Menu Projects - click "Create BaseLink.lst from Mode Selected"
project files along with a pre-made dll are in the zip.
John Z
-
AddIn_EnumProjectFiles macro might be useful for creating cmd-files ?
-
I was thinking along that line too. An Add-In could create the entire make_all.bat file and the BaseLink.lst file then the three other files stay static if just called and fed from the master. Basically an embedded a batch file template within the Add-in, or even read in and written out, filling in the blanks along the way to make a working make_all.bat.
The poccx method is entirely smoother and transparent once implemented, but having another method in reserve doesn't hurt. Maybe, maybe...but small audience I'm guessing.
John Z
-
The poccx method is entirely smoother and transparent once implemented, but having another method in reserve doesn't hurt. Maybe, maybe...but small audience I'm guessing.
poccx is just a temporary solution for small group with 24H2.
generating batch files for other C compilers might be useful.
-
I don't understand why you spend your time like this. There aready have working solutions. Why continue like this? :-\
-
Both of the solutions are nice. Thanks to Timo and John.