Thread: Compile question?

  1. #1
    Registered User
    Join Date
    Apr 2008
    Posts
    2

    Compile question?

    I'm just trying to compile a simple Hello World program in the latest Visual Studio but when I hit compile I get the following message:
    'LINK : fatal error LNK1104: cannot open file 'kernel32.lib'

    I'm pretty new at Visual Studio and C++, how do I fix this problem? Any help would be greatly appreciated, thank you.

  2. #2
    Jack of many languages Dino's Avatar
    Join Date
    Nov 2007
    Location
    Chappell Hill, Texas
    Posts
    2,332
    Sounds like you didn't start off with the right flavor project. Or, you did start off with the right project, but then grew your scope to using facilities your project wasn't configured for.

    It can most likely be fixed manually by linker parms and switches, but it easier for you (and me!) to just start over. I suspect you haven't invested too much time in Hello World, so perhaps you can just cut and paste into the new project.

    Todd
    Mainframe assembler programmer by trade. C coder when I can.

  3. #3
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Actually, I'm not sure it's the right flavour of project that is the problem here.

    I would hazard a guess that the real problem here is that the linker is not able to find system libraries - perhaps the lib file is not actually supplied with the Visual Studio, and you have to install the Windows SDK (aka Platform SDK) to get the .lib file for Kernel32.dll?

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  4. #4
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    For Visual Studio Express, you indeed have to install the Platform SDK to get kernel32.lib. But a simple console application shouldn't have a need to link against it.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  5. #5
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by CornedBee View Post
    But a simple console application shouldn't have a need to link against it.
    Indeed, as long as the functions used are standard C library functions, it shouldn't need any extra libraries. But if you want to use some specific Windows functions, then you may need kernel32.lib. For example CreateProcess() is a kernel32.lib function. (There are more than a 1000 functions in Kernel32.lib)

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  6. #6
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Every application, console or not, links against kernel32.dll.
    But perhaps the C/C++ runtime links against kernel32.dll too?
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  7. #7
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    The runtime links against kernel32.dll, but it's pre-built, so you don't need kernel32.lib.
    A pure console application should not link against anything but msvcrtxx.dll and (in C++) msvcppxx.dll (or something like that).
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Another mock question that doesnt compile!
    By spadez in forum C Programming
    Replies: 12
    Last Post: 04-16-2009, 12:00 PM
  2. another do while question
    By kbpsu in forum C++ Programming
    Replies: 3
    Last Post: 03-23-2009, 12:14 PM
  3. Design layer question
    By mdoland in forum C# Programming
    Replies: 0
    Last Post: 10-19-2007, 04:22 AM
  4. opengl DC question
    By SAMSAM in forum Game Programming
    Replies: 6
    Last Post: 02-26-2003, 09:22 PM
  5. Very simple question, problem in my Code.
    By Vber in forum C Programming
    Replies: 7
    Last Post: 11-16-2002, 03:57 PM