News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

What is crt.lib?

Started by rogerio, April 24, 2009, 07:41:02 PM

Previous topic - Next topic

rogerio

I downloaded strsafeinc.zip and strsafe.zip from http://www.masm32.com/board/index.php?topic=8022.msg58718#msg58718 after finding an issue with the SDK files. When I try to link the following shows up: LINK : fatal error LNK1104: cannot open file "crt.lib". I have tried to locate crt.lib, but it doesn't seem to exist. I also added msvcrt and crtdll to the include/includelib areas.

Using the SDK .inc file says it can't find _StringCbPrintfA.

What is the problem? Thanks...

I have removed the change in the title as this forum is used as reference by many programmers and is not to be treated as a single problem solving venue.

Admin.

MichaelW

As far as I know crt.lib is from PellesC, and to use the PellesC strsafe.lib you will need crt.lib and possibly other libraries. Strsafe.inc contains prototypes for the functions in strsafe.lib. To actually use the functions your assembled object module must be linked with strsafe.lib. I was able to use the SDK strsafe.lib no problem.

; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
    include \masm32\include\masm32rt.inc

    ; Both of the following files were placed in the current directory:

    include strsafe.inc         ; this from strsafeinc.zip
    includelib strsafe.lib      ; this from SDK\lib

; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
    .data
      szDest db 30 dup(0)
    .code
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
start:
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««

    invoke StringCbPrintf, ADDR szDest, 30, chr$("%s %d + %d = %d."),
                           chr$("The answer is"), 1, 2, 3

    print ustr$(eax),13,10,13,10

    print ADDR szDest,13,10,13,10

    inkey "Press any key to exit..."
    exit
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
end start

SDK example for StringCbPrintf:

int const arraysize = 30;
TCHAR pszDest[arraysize];
size_t cbDest = arraysize * sizeof(TCHAR);

LPCTSTR pszFormat = TEXT("%s %d + %d = %d.");
TCHAR* pszTxt = TEXT("The answer is");

HRESULT hr = StringCbPrintf(pszDest, cbDest, pszFormat, pszTxt, 1, 2, 3);

These from SDK strsafe.h:

#define STRSAFE_E_INSUFFICIENT_BUFFER ((HRESULT)0x8007007AL)
#define STRSAFE_E_INVALID_PARAMETER   ((HRESULT)0x80070057L)
#define STRSAFE_E_END_OF_FILE         ((HRESULT)0x80070026L)

#define SUCCEEDED(Status) ((HRESULT)(Status) >= 0)
#define FAILED(Status)     ((HRESULT)(Status)<0)

eschew obfuscation

rogerio

Thanks MichaelW. I copied your code and I still get the error _StringCbPrintfA. I used the same include and includelib files that you did and I did not get back any errors that the linker did not find them. Can this be a problem with the linker command line? Here is mine: LINK.EXE /SUBSYSTEM:WINDOWS /RELEASE /VERSION:4.0. Here is the code also:
.386
.model flat, stdcall  ;32 bit memory model
option casemap :none  ;case sensitive

    include \masm32\include\masm32rt.inc

    ; Both of the following files were placed in the current directory:

    include strsafe.inc         ; this from strsafeinc.zip
    includelib strsafe.lib      ; this from SDK\lib

; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
    .data
      szDest db 30 dup(0)
    .code
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
start:
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««

    invoke StringCbPrintf, ADDR szDest, 30, chr$("%s %d + %d = %d."),
                           chr$("The answer is"), 1, 2, 3

    print ustr$(eax),13,10,13,10

    print ADDR szDest,13,10,13,10

    inkey "Press any key to exit..."
    exit
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
end start

MichaelW

I named the source test.asm. With strsafe.inc from strsafeinc.zip and strsafe.lib from the SDK in the current directory I can build a working EXE with this batch file:

if exist test.obj del test.obj
if exist test.exe del test.exe

\masm32\bin\ml /c /coff test.asm

pause

\masm32\bin\Link /SUBSYSTEM:CONSOLE /OPT:NOREF test.obj

pause


By placing strsafe.inc and strsafe.lib in the current directory, there is no problem with the system using some other file of the same name because it was specified in an environment variable.

Also, the first three statements in your source:

.386
.model flat, stdcall  ;32 bit memory model
option casemap :none  ;case sensitive

Duplicate statements in masm32rt.inc.
eschew obfuscation

rogerio

Here is the complete test, still getting the crt.lib error - see LinkOutput.txt. Thanks...

[attachment deleted by admin]

MichaelW

You're using the wrong strsafe.lib. The one from PellesC is 56110 bytes, modified on 6/6/2006. The one I am using from the SDK is 64604 bytes, modified on 3/26/2003. I assumed that you had the SDK because you mentioned the SDK .inc file in the first post in this thread. On my system the path is:

C:\Program Files\Microsoft SDK\Lib
eschew obfuscation

rogerio

I think you have found the problem, here is file info:

\Program Files\Microsoft SDKs\Windows\v6.1\Lib
Modified 1/18/2008
Size 23.6 kb

This is where I got it at: http://www.microsoft.com/downloads/details.aspx?FamilyId=A55B6B43-E24F-4EA3-A93E-40C0EC4F68E5&displaylang=en

You are right, the file is the wrong size and I am not familiar with PellesC. I did a search and all I came up with is the C-source code. Can you please upload your file so I can get a copy? Thanks...

MichaelW

Sorry, I don't have that right under the EULA. Why not download and install the PSDK? To me, the documentation alone is well worth the effort.
eschew obfuscation

rogerio

Thanks MichaelW. After doing some more research I was able to find PellesC and its' SDK. I don't know what PellesC is, but I am going to look at it. BTW, it contained crt.lib which allowed linking to occur.

Vortex

Hi rogerio,

crt.lib is Pelle's C run-time library. This thread can help you to use the library with Masm :

Using Pelle's C run-time library with Masm

rogerio

Thank Vortex, all information is valuable.