Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 362987

Summary: CDT Visual C++ Support failed to link kernel32.lib
Product: [Tools] CDT Reporter: Meng-Yuan Huang <myh>
Component: cdt-buildAssignee: cdt-build-inbox <cdt-build-inbox>
Status: CLOSED DUPLICATE QA Contact: Jonah Graham <jonah>
Severity: normal    
Priority: P3 CC: aegges, cdtdoug, charleybin, malaperle, myh, sscheme
Version: 8.0.2   
Target Milestone: ---   
Hardware: PC   
OS: Windows 7   
Whiteboard:

Description Meng-Yuan Huang CLA 2011-11-06 06:35:40 EST
Build Identifier: Indigo 20110916-0149

My CDT is version 8.0 and CDT Visual C++ Support is version 1.0.0.201109151620.
My compiler is Visual C++ 2010.
My OS is Windows 7 64-bit.

I meet a link error when I build a simple hello world program.
The following shows the error message:
-------------------------------------------
**** Rebuild of configuration Debug for project a ****

**** Internal Builder is used for build               ****
cl /c /EHs /MD /Zi /nologo /Foa.obj ..\a.cpp
a.cpp
link /debug /nologo /OUT:a.exe a.obj
LINK : fatal error LNK1104: cannot open file 'kernel32.lib'
Build error occurred, build is stopped
Time consumed: 1454  ms.  
-------------------------------------------

I have googled the error LNK1104.
This error comes from LIB environment variable doesn't contain this path:
C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Lib
kernel32.lib is in the path.

I think the better method to solve this problem could be
CDT Visual C++ Support supported to execute
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin\vcvars32.bat
and get the correct environment variables for compiling...
Or any other idea?

Reproducible: Always

Steps to Reproduce:
1. Create a C++ project.
2. Write a hello world program.
3. Build the program.
Comment 1 charley bin CLA 2012-01-30 00:28:06 EST
Hi,
I just occurred the same error with you. here is the reason why it's not work for us from my personal understanding and how I resolved it.

The reason is: "because of the eclipse didn't know which platform you are working, and which architecture your source code build for". e.g. ia64 or i386 or others. the platform associated library may required by the compiler. eclipse do not know what's required and where it is, it's just print out the error message for you.  so, the conclusion is that you may need to specify the path to  kernel32.lib manually. 


below is the steps to fix kernel32.lib not found problem, I think it's could helpful to you:

1, Install Microsoft Windows SDK v7.0 on your machine. (or other versions)

2, In the C/C++ Projects view, right-click the project, and select Properties.

3, Go to C/C++ General > Paths and Symbols > Library Paths and add the path to kernel32.lib, for example, my path is (with single quotation):
'C:/Program Files/Microsoft SDKs/Windows/v7.0A/Lib/kernel32.lib'

(IMPORTANT: using Single quotation marks your path.)

4, build your Hello-World project again. you could see the hello-world output from eclipse debug console.



Regards.

Bin
Comment 2 Meng-Yuan Huang CLA 2012-01-30 00:45:20 EST
Hi Bin,

Thanks for your information.
I have known the solution that how to manually add the path to kernel32.lib.

However, I am not sure whether or not Eclipse can automatically acquires build settings from vcvars32.bat.
Comment 3 Marc-André Laperle CLA 2020-10-25 15:58:44 EDT
This was fixed as part of bug 567169. vsvarsall.bat is now used to detect the environment variables (PATH, INCLUDE, LIB). One flaw is that amd64 is the hard-coded target for now, this would be addressed separately.

*** This bug has been marked as a duplicate of bug 567169 ***