Closed headscott closed 6 months ago
I think it is misunderstanding of libraries on various platforms.
you are creating static library, you cannot use linker tool but you need to use librarian.
If you create all object files which you want to add to some library you can use OW librarian following way
wlib -n <library name> <list of object files for adding>
see OW documentation
Anyway for linking executable you need linker, the command can be like
wlink sys <target system id> name test file { <space separated list of object files> } library { <space separated list of libraries> }
see OW documentation
I want to create an executable from my test.o file. It has no reference to any printf function by itself, so I wanted to add the library from my mingw gcc installation and add it while linking, so that there is no missing reference.
If I use ld I would do something like that:
ld test.o -L C:/msys2/mingw32/lib -lmsvcrt
Is there an equivalent way for wlink? wlib would create libraries, but I have my libmsvcrt.a file, so I don't need to create one.
If target is WIN32 then command for linking should be something like.
wlink sys nt name test.exe opt nod file test.o lib libmsvcrt.a
but because you not use Watcom CRTL then you need specify your startup code etc.
Okay thank you. I found out, what my problem was: I needed to convert my object files from .o to .obj if I wanted to use that library or I need to make my own library from all needed object files with wlib and add this one with lib option. I am not sure why I just need to convert one of them and not both, but it worked anyways now.
No you not need to convert it. You have two possibilty
I got the version V2.0 from 29th of april this year.
So I tried to compile this code (test.c) :
By the following command:
gcc test.c -w -ffreestanding -c -o test.o
gcc here is from djgpp-mingw-gcc1220-standalone from github: https://github.com/andrewwutw/build-djgpp but I think it makes no difference here if its this cross compiler oder standard gnu gcc.
Then I wanted to create an executable from that test.o file by using wlink by the following command:
wlink file test.o file libs/libmsvcrt.a
I also tried these (with exact same result):
libmsvcrt.a (path is msys2/mingw32/lib/libmsvcrt.a) is a library I got from my mingw installation, which provides a definition for printf function as far as I know.
Executing these commands does not output any exceptions, but no executable has been created by wlink. Wlink prints this:
Thats it, no errors. If I do the same but with this code (another version of test.c):
and the same steps, but
wlink file test.o
It works fine and test.exe is been generated. So it seems that the .a libraries here is the problem. How can i fix it, because for printf I need a library?
This is just a minimal example, the real project is much bigger, so i think getting all the object files from that .a file via
ar xv libmsvcrt.a
ans searching for all .o files of all the standard c functions I am using and including them while linking by hand doesn't seem right to me, even though this could work.