views:

306

answers:

3

Here is a very simple C program:

#include <stdio.h>

int main (int argc, char *argv[]) {

    printf("sizeof(short) = %d\n",(int)sizeof(short));
    printf("sizeof(int) = %d\n",(int)sizeof(int));
    printf("sizeof(long) = %d\n",(int)sizeof(long));
    printf("sizeof(long long) = %d\n",(int)sizeof(long long));
    printf("sizeof(float) = %d\n",(int)sizeof(float));
    printf("sizeof(double) = %d\n",(int)sizeof(double));

    return 0;
}

While it compiles fine on Win32 (command line: cl main.c), it does not using the Win64 compiler ("c:\Program Files(x86)\Microsoft Visual Studio 9.0\VC\bin\amd64\cl.exe" main.c). Specifically, it sais "error LNK2019: unresolved external symbol printf referenced in function main". As far as I understand this, it can not link to printf, right?

Obviously, I have Microsoft Visual C++ Compiler 2008 (Standard enu) x86 and x64 installed and am using the 64-bit flavor of Windows (7).

What is the problem here?

UPDATE:
OK, now I ran vcvarsall.bat amd64. It sais "The specified configuration type is missing. The tools for this configuration might not be installed.". As mentioned, the compiler clearly is installed??

A: 

Are you on a 32bit or 64bit system? I'm guessing from the path that the 64bit standard libraries aren't available, at least not in that directory.

CWF
I updated the post accordingly. I am on Windows 7 x64
BastiBechtold
+2  A: 

There's something wrong with your setup. It compiles & link fine for me.

D:>cl test.cpp Microsoft (R) C/C++ Optimizing Compiler Version 15.00.30729.01 for x64 Copyright (C) Microsoft Corporation. All rights reserved.

test.cpp Microsoft (R) Incremental Linker Version 9.00.30729.01 Copyright (C) Microsoft Corporation. All rights reserved.

/out:test.exe test.obj

D:>

Did you run vcvarsall.bat with the right options to set up the environment variables before you try running cl.exe? Something along the line of

"C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\vcvarsall.bat" x86_amd64

KTC
Nope. Will do...
BastiBechtold
+1  A: 

If you look at vcvarsall.bat it will print the specified configuration missing statement if certain batch files are missing.

For the amd64 option this file must exist:

C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\bin\amd64\vcvarsamd64.bat
daddyman
it's not there. Do you have an idea what is wrong with my installation? (I did not manipulate it or something)
BastiBechtold
Is just the file missing or the whole directory? The "bin\amd64" directory is the 64-bit compiler (cl.exe is a 64-bit application). The bin\x86_amd64 is the 64-bit cross compiler (cl.exe is a 32-bit application). Maybe you only have the 32-bit version of the 64-bit compiler installed? If you try "vcvarsdll x86_amd64" does it work?
daddyman
just the one file. I guess I am missing the SP1, which is currently downloading.
BastiBechtold
If bin\x86_amd64 is there, then why don't you use the cross compiler?
KTC
If you don't have SP1 that would be a good first step. Otherwise - you could go to Add/Remove programs and do a Repair on Visual Studio 2008 to see if the file appears (or reappears).
daddyman
Yeah, SP1 fixed it! Thanks!
BastiBechtold