I have downloaded the IUP iup-3.25_Win64_vc15_lib.zip (the latest x64 bit VS version they provided) file and have extracted it to my project (in a sub folder called Library). I am trying to compile the following:
#include "Librarty/include/iup.h"
int main(int argc, char **argv) {
IupOpen(&argc, &argv);
IupMessage("TEST", "Test App");
IupClose();
return 0;
}
I have added the path to the header files by selecting
Project > Properties > Additional Include Libraries > File path
It is set to Library/include
Next I have added the .lib files by:
Project > Properties > Linker > Additional Library Dictionaries
The method taken from this answer.
Finally I added the .rc file by:
Under Solutions Explorer > Project Name > Add Existing Item > Given File Path
Set that to Library/ext/iup.rc
I then tried to compile my project and got the following error (I have set the compiler to x64 release):
1>------ Build started: Project: IUP, Configuration: Release x64 ------
1>main.c
1>main.obj : error LNK2001: unresolved external symbol IupOpen
1>main.obj : error LNK2001: unresolved external symbol IupMessage
1>main.obj : error LNK2001: unresolved external symbol IupClose
1>C:\Users\Simon\Desktop\Learn\IUP\x64\Release\IUP.exe : fatal error LNK1120: 3 unresolved externals
1>Done building project "IUP.vcxproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
What do I need to do to get it to build?
Project Path:
C:\Users\Simon\Desktop\Learn\IUP\
IUP library:
C:\Users\Simon\Desktop\Learn\IUP\Library
EDIT: complete linker:
/OUT:"C:\Users\Simon\Desktop\Learn\IUP\x64\Release\IUP.exe" /MANIFEST /LTCG:incremental /NXCOMPAT /PDB:"C:\Users\Simon\Desktop\Learn\IUP\x64\Release\IUP.pdb" /DYNAMICBASE "kernel32.lib" "user32.lib" "gdi32.lib" "winspool.lib" "comdlg32.lib" "advapi32.lib" "shell32.lib" "ole32.lib" "oleaut32.lib" "uuid.lib" "odbc32.lib" "odbccp32.lib" /DEBUG:FULL /MACHINE:X64 /OPT:REF /PGD:"C:\Users\Simon\Desktop\Learn\IUP\x64\Release\IUP.pgd" /MANIFESTUAC:"level='asInvoker' uiAccess='false'" /ManifestFile:"x64\Release\IUP.exe.intermediate.manifest" /OPT:ICF /ERRORREPORT:PROMPT /NOLOGO /LIBPATH:"C:\Users\Simon\Desktop\Learn\IUP\Librarty" /TLBID:1
Related
I have encountered problem with linking static lib - when there no windows.h and calls to WinAPI, it links and works fine, but when they used, I get this error when building:
error: linking with `link.exe` failed: exit code: 1120
note: external-test.lib(library_win32.cpp.obj) : error LNK2019: unresolved external symbol __imp_MessageBoxW referenced in function init_window
In list of all used libs, there no user32.lib. Maybe it is the problem? How can I tell linker to use it
note: "C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\BuildTools\\VC\\Tools\\MSVC\\14.16.27023\\bin\\HostX64\\x64\\link.exe" ... "kernel32.lib" "advapi32.lib" "ws2_32.lib" "userenv.lib" "msvcrt.lib"
Here build script:
fn main() {
println!("cargo:rustc-link-search={}/src/external",env::var("CARGO_MANIFEST_DIR").unwrap());
}
Solution was simple - link user32 in build script
I'm trying to get familiar with Eiffel language so I've installed Eiffel Studio 18 and created a Graphics application. Compilation failed with message:
Preparing C compilation using already configured msc C compiler...
ERROR: Cannot start "nmake".ERROR: Cannot start "nmake".
Documentation suggested that espawn utility may show available toolchains, however it seems to crash:
PS C:\Program Files\Eiffel Software\EiffelStudio 18.07 GPL\tools\spec\win64\bin> & "C:\Program Files\Eiffel Software\EiffelStudio 18.07 GPL\tools\spec\win64\bin\espawn.exe" -l
Eiffel Environment Command Spawn Utility - Version: 18.07
Copyright Eiffel Software 1985-2018. All Rights Reserved.
Available C/C++ compilers:
espawn: system execution failed.
Following is the set of recorded exceptions:
******************************** Thread exception *****************************
In thread Root thread 0x0 (thread id)
*******************************************************************************
-------------------------------------------------------------------------------
Class / Object Routine Nature of exception Effect
-------------------------------------------------------------------------------
APPLICATION root's creation Segmentation violation:
<000000000363C588> Operating system signal. Exit
-------------------------------------------------------------------------------
APPLICATION root's creation
<000000000363C588> Routine failure. Exit
-------------------------------------------------------------------------------
Unfortunately I couldn't find any toolchain related stuff except for that espawn util so I've tried to launch Eiffel Studio from VS development command prompt hoping that it may implicitly rely on some environment variables. This indeed helped, however compilation still fails with linker error:
Preparing C compilation using already configured msc C compiler...
big_file_C28_c.c
eoption.c
big_file_E2_c.c
big_file_C26_c.c
big_file_C27_c.c
big_file_C30_c.c
big_file_C29_c.c
big_file_C31_c.c
eref.c
epoly.c
esize.c
big_file_C25_c.c
big_file_C24_c.c
big_file_C23_c.c
big_file_C22_c.c
big_file_C21_c.c
big_file_C20_c.c
big_file_C19_c.c
eplug.c
eskelet.c
enames.c
evisib.c
big_file_C18_c.c
big_file_C17_c.c
big_file_C16_c.c
big_file_C15_c.c
big_file_C13_c.c
big_file_C14_c.c
ececil.c
big_file_C12_c.c
einit.c
eparents.c
big_file_C11_c.c
big_file_C10_c.c
big_file_C9_c.c
big_file_C8_c.c
big_file_C7_c.c
big_file_C6_c.c
big_file_C5_c.c
big_file_C4_c.c
big_file_C3_c.c
big_file_C2_c.c
big_file_C1_c.c
Скопировано файлов: 1.
emain.c
Microsoft (R) Windows (R) Resource Compiler Version 10.0.10011.16384
Copyright (C) Microsoft Corporation. All rights reserved.
Microsoft (R) Incremental Linker Version 14.16.27024.1
Copyright (C) Microsoft Corporation. All rights reserved.
-STACK:5000000 -NODEFAULTLIB:libc -STACK:5000000 -NODEFAULTLIB:libc -SUBSYSTEM:WINDOWS -OUT:my_wel_application_1.exe
e1\emain.obj
"C:\Program Files\Eiffel Software\EiffelStudio 18.07 GPL\studio\spec\win64\lib\msc\finalized.lib" "C:\Program Files\Eiffel Software\EiffelStudio 18.07 GPL\library\wel\spec\msc\win64\lib\wel.lib"
USER32.lib WS2_32.lib ADVAPI32.lib GDI32.lib SHELL32.lib MSIMG32.lib COMDLG32.lib UUID.lib OLE32.lib OLEAUT32.lib COMCTL32.lib MPR.LIB SHLWAPI.LIB WINSPOOL.LIB
my_wel_application_1.res
E2\Eobj2.lib E1\eparents.obj E1\einit.obj E1\ececil.obj E1\evisib.obj
E1\enames.obj E1\eskelet.obj E1\eplug.obj E1\esize.obj E1\epoly.obj
E1\eref.obj E1\eoption.obj C31\Cobj31.lib C30\Cobj30.lib C29\Cobj29.lib
C28\Cobj28.lib C27\Cobj27.lib C26\Cobj26.lib C25\Cobj25.lib C24\Cobj24.lib
C23\Cobj23.lib C22\Cobj22.lib C21\Cobj21.lib C20\Cobj20.lib C19\Cobj19.lib
C18\Cobj18.lib C17\Cobj17.lib C16\Cobj16.lib C15\Cobj15.lib C14\Cobj14.lib
C13\Cobj13.lib C12\Cobj12.lib C11\Cobj11.lib C10\Cobj10.lib C9\Cobj9.lib
C8\Cobj8.lib C7\Cobj7.lib C6\Cobj6.lib C5\Cobj5.lib C4\Cobj4.lib
C3\Cobj3.lib C2\Cobj2.lib C1\Cobj1.lib
finalized.lib(econsole.obj) : error LNK2001: unresolved external symbol __iob_func
finalized.lib(console.obj) : error LNK2001: unresolved external symbol __iob_func
finalized.lib(file.obj) : error LNK2001: unresolved external symbol __iob_func
finalized.lib(main.obj) : error LNK2001: unresolved external symbol __iob_func
finalized.lib(except.obj) : error LNK2001: unresolved external symbol __iob_func
finalized.lib(sig.obj) : error LNK2001: unresolved external symbol __iob_func
finalized.lib(option.obj) : error LNK2001: unresolved external symbol __iob_func
finalized.lib(main.obj) : error LNK2019: unresolved external symbol _set_output_format referenced in function eif_rtinit
finalized.lib(run_idr.obj) : error LNK2001: unresolved external symbol sprintf
finalized.lib(except.obj) : error LNK2001: unresolved external symbol sprintf
finalized.lib(out.obj) : error LNK2001: unresolved external symbol sprintf
finalized.lib(file.obj) : error LNK2001: unresolved external symbol sprintf
finalized.lib(store.obj) : error LNK2001: unresolved external symbol sprintf
finalized.lib(econsole.obj) : error LNK2019: unresolved external symbol vfprintf referenced in function print_err_msg
finalized.lib(file.obj) : error LNK2019: unresolved external symbol fscanf referenced in function rt_swallow_nl
finalized.lib(retrieve.obj) : error LNK2019: unresolved external symbol sscanf referenced in function iread_header_new
finalized.lib(run_idr.obj) : error LNK2001: unresolved external symbol sscanf
my_wel_application_1.exe : fatal error LNK1120: 6 unresolved externals
NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\bin\HostX64\x64\link.EXE"' : return code '0x460'
Stop.
The compilation error when running from VS development command prompt is related to the mismatch between C compiler version and used Eiffel run-time library. Setting the corresponding environment variable before launching the compilation should fix the issue:
set ISE_C_COMPILER=msc_vc140
As to the original error, for some reason, C compilation fails on some machines, because EiffelStudio cannot find VS. The issue has even become a FAQ.
I'm using VS2015 Community. I have obtained some C code that I'm trying to build. It is all in C and I have made a project as a Console Application.
When I build I get the below errors. The problem is that __stdio_common_vsprintf_s cannot be found during the link process. So I searched the internet for the symbols but don't get any useful information.
I am using the Runtime Library setting called Multi-threaded (/MT).
I have tried adding #define STDC_WANT_LIB_EXT1 1 before all includes but that did not help. I have searched for this problem and have not found any postings that help.
So I searched all of the VS libraries and got lots of hits but I don't know which are definitions and which are references. Then I searched all of the .h files in the VS include folder but no hits.
I suspect there may be another library that I need but don't know what it is. Does anyone have any ideas?
1>LIBCMT.lib(_error_.obj) : error LNK2019: unresolved external symbol ___stdio_common_vsprintf_s referenced in function __vsprintf_s_l
1>LIBCMT.lib(_pdblkup_.obj) : error LNK2019: unresolved external symbol ___vcrt_GetModuleFileNameW referenced in function "int __cdecl _RTC_GetSrcLine(unsigned char *,wchar_t *,unsigned long,int *,wchar_t *,unsigned long)" (?_RTC_GetSrcLine##YAHPAEPA_WKPAH1K#Z)
1>LIBCMT.lib(_pdblkup_.obj) : error LNK2019: unresolved external symbol ___vcrt_LoadLibraryExW referenced in function "struct HINSTANCE__ * __cdecl GetPdbDllFromInstallPath(void)" (?GetPdbDllFromInstallPath##YAPAUHINSTANCE__##XZ)
1>MSVCRTD.lib(_chandler4gs_.obj) : error LNK2019: unresolved external symbol __except_handler4_common referenced in function __except_handler4
1>W:\efifs\Debug\testing.exe : fatal error LNK1120: 6 unresolved externals
Here are my options:
Compile
----------
/GS
/analyze-
/W3
/Zc:wchar_t
/I"W:\efifs\\gnu-efi\inc"
/I"W:\efifs\\gnu-efi\inc\ia32"
/I"W:\efifs\\grub\include"
/I"W:\efifs\\grub-core\lib\minilzo"
/I"W:\efifs\testing\"
/I"W:\efifs\\gnu-efi\inc\protocol"
/I"W:\efifs\\gnu-efi\lib"
/I"W:\efifs\\include"
/I"W:\efifs\\grub\grub-core\lib\minilzo"
/I"W:\efifs\.msvc"
/ZI
/Gm
/Od
/Fd"Debug\vc140.pdb"
/Zc:inline
/fp:precise
/D "__STDC_WANT_LIB_EXT1__=1"
/D "_UNICODE"
/D "UNICODE"
/D "GRUB_FILE=__FILE__"
/D "HAVE_USE_MS_ABI"
/D "GNU_EFI_USE_EXTERNAL_STDARG"
/D "DRIVERNAME=testing"
/D "WIN32"
/D "_DEBUG"
/D "_CONSOLE"
/errorReport:prompt
/WX-
/Zc:forScope
/RTC1
/Gd
/Oy-
/MT
/Fa"Debug\"
/EHsc
/nologo
/Fo"Debug\"
/Fp"Debug\testing.pch"
Link
-----
/OUT:"W:\efifs\Debug\testing.exe"
/MANIFEST
/NXCOMPAT
/PDB:"W:\efifs\Debug\testing.pdb"
/DYNAMICBASE "efifs.lib" "grub.lib" "gnu-efi.lib" "kernel32.lib" "user32.lib" "gdi32.lib" "winspool.lib" "comdlg32.lib" "advapi32.lib" "shell32.lib" "ole32.lib" "oleaut32.lib" "uuid.lib" "odbc32.lib" "odbccp32.lib"
/MACHINE:X86
/INCREMENTAL
/PGD:"W:\efifs\Debug\testing.pgd"
/SUBSYSTEM:CONSOLE
/MANIFESTUAC:"level='asInvoker' uiAccess='false'"
/ManifestFile:"Debug\testing.exe.intermediate.manifest"
/ERRORREPORT:PROMPT
/NOLOGO
/LIBPATH:"W:\efifs\testing\\grub"
/LIBPATH:"W:\efifs\testing\\efifs"
/LIBPATH:"W:\efifs\testing\\gnu-efi"
/TLBID:1
If you look how vsprintf is declared you can trace it corecrt_stdio ... where it says to inline it.
I had some old DLL which were linking against old msvcrt and trying to import vsprintf from it but seems like VS2015 have new headers and trying to inline it.
Setting _NO_CRT_STDIO_INLINE helped to resolve it, Enjoy.
Edit: Also https://msdn.microsoft.com/en-us/library/bb531344.aspx
You configuration appears to be incorrect. You don't seem to be linking with a couple of new libraries added in Visual Studio 2015's reorganization of the C runtime library. You also appear to linking with both the release static (/MT) and debug DLL (/MDd) version of the same library, specifically LIBCMT.lib and MSVCRTD.lib.
The symbol ___stdio_common_vsprintf_s can be found in the in Universal CRT which part of the Windows 10 SDK. The release static version of the library is called libucrt.lib. The other unresolved symbols are part of "vcruntime" library which is part of Visual Studio 2015. The name of it's release static version is libvcruntime.lib.
It not clear why you're not linking with the correct libraries. Normally this handled automatically for you. You'll need to check to your project's configuration settings to see where you've overridden the default behaviour.
You need insert this line
#define _NO_CRT_STDIO_INLINE
According to the C standard annex K
K.3.1.1 Standard headers
The functions, macros, and types declared or defined in K.3 and its subclauses are not
declared or defined by their respective headers if _ _STDC_WANT_LIB_EXT1_ _ is
defined as a macro which expands to the integer constant 0 at the point in the source file
where the appropriate header is first included.
Meaning that in order to use the "_s" functions such as vsprintf_s, which are all found in the mentioned annex, you must define that macro to a value other than 0 before including the header files.
#define __STDC_WANT_LIB_EXT1__ 1
#include <stdarg.h>
#include <stdio.h>
I suspect that you must have a C11 compiler. Whether or not Visual Studio follows that standard, I have no idea. It is notorious for its poor standard conformance.
I have written a C Program which calls the function, GetModuleInformation() which is defined in psapi.h
I am using Microsoft Visual Studio C++ command line compiler (cl.exe) for compiling and linking the program.
I have included the psapi.h header file:
#include <psapi.h>
when I try to compile using:
cl program.c
It generates the object file, however fails during the linking stage with the error:
program.obj : error LNK2019: unresolved external symbol _GetModuleInformation#16 ref
erenced in function _main
program.exe : fatal error LNK1120: 1 unresolved externalsprogram.obj : error LNK2019: unresolved external symbol _GetModuleInformation#16 ref
I also place the psapi.lib file in the same folder where the source code file (program.c) is placed, however even then I get the same error message as above.
How do I successfully link it using the command line compiler (cl.exe)?
Method 1
If you want to compile from the command line with cl.exe you can use the /link option to specify linker options :
cl /TC program.c /link psapi.lib
Method 2
The following pragma directive causes the linker to search in your source file for the psapi.lib library while linking .
#pragma comment( lib, "psapi.lib" )
Possible reason for your errors can be, if psapi.lib is missing in a list of additional libraries of linker.
To resolve this, use the following /LIBPATH option :
cl /TC program.c /link Psapi.Lib /LIBPATH:C:\MyLibFolder\
Where C:\MyLibFolder specifies a path to the folder, that contains your psapi.lib .
Also, you can try to set the proper /SUBSYSTEM option .
For a Console application use :
/SUBSYSTEM:CONSOLE
Solution to similar problem here .
Example on using the GetModuleInformation function :
#include <windows.h>
#include <stdio.h>
#include <psapi.h>
#pragma comment( lib, "psapi.lib" )
int main(void)
{
MODULEINFO minfo = {0};
GetModuleInformation( GetCurrentProcess(), GetModuleHandle( "psapi.dll" ), &minfo, sizeof(minfo) );
/* printf("%X", minfo.lpBaseOfDll); /* The load address of the module */
return 0;
}
The code has been tested on Windows 7 and XP .
The output from linking session is :
program.c
/out:program.exe
psapi.lib
/LIBPATH:C:\MyLibFolder\
/SUBSYSTEM:CONSOLE
/VERBOSE
program.obj
Starting pass 1
Processed /DEFAULTLIB:uuid.lib
Processed /DEFAULTLIB:LIBCMT
Processed /DEFAULTLIB:OLDNAMES
Searching libraries
Searching C:\MyLibFolder\psapi.lib:
Found _GetModuleInformation#16
Referenced in program.obj
Loaded psapi.lib(PSAPI.DLL)
Found __IMPORT_DESCRIPTOR_PSAPI
Referenced in psapi.lib(PSAPI.DLL)
Loaded psapi.lib(PSAPI.DLL)
Found __NULL_IMPORT_DESCRIPTOR
Referenced in psapi.lib(PSAPI.DLL)
Loaded psapi.lib(PSAPI.DLL)
...
If vsvars32.bat and all appropriate environment variables in your Visual Studio are set correctly the above linker options will produce a valid executable(.exe) file.
I am trying to compile a C program using the Intel icl compiler under MINGW/64. The program uses the following code:
#include <Userenv.h>
HANDLE process;
HANLDE token;
GetUserProfileDirectory(process, TOKEN_QUERY, &ptoken)
I am using the following compile command:
$ icl -g -DMINGW32 -DTESTMAIN user.c -o user -UserEnv.Lib
and I am linking against the UserEnv.Lib from the Microsoft SDK.
Intel(R) C++ Intel(R) 64 Compiler XE for applications running on Intel(R) 64, Version Microsoft (R) Incremental Linker Version 9.00.21022.08
-out:user.exe
user.obj
user.obj : error LNK2019: unresolved external symbol __imp_GetUserProfileDirectoryA referenced in function main
Any idea how to solve this problem?
SOLUTION:
The solution is to use
/link /c/Program\ Files/Microsoft\ SDKs/Windows/v6.0A/Lib/x64/UserEnv.Lib /c/Program\ Files/Microsoft\ SDKs/Windows/v6.0A/Lib/x64/A
I copied the file UserEnv.lib from the Microsoft SDK (x64, 6.0) into the current working directory and compiled the program with
$ icl test.c -DMINGW32 ./UserEnv.Lib
LNK2019: unresolved external symbol __imp_GetUserNameA referenced in function main test.obj : error LNK2019: unresolved external symbol __imp_OpenProcessToken referenced in function main test.obj : error LNK2019: unresolved external symbol –
and I am still getting the unresolved symbols.
Olaf
You need to add userenv.lib to your input libraries for the linker to see GetUserProfileDirectory().
EDIT: It's been a while since I've touched an Intel compiler, but IIRC you're supposed to use /link to introduce linker options:
$ icl test.c -DMINGW32 /link ./UserEnv.Lib