pdcurses linkage using Visual Studio 2010 - c

This is doing my nut in. I'm just trying to include pdcurses (i.e. ncurses for windows) into a test program. Linkage though is failing.
Using Visual Studio 2010.
I'm fully aware of setting up the correct link additional libraries path and to list the libraries themselves. No joy.
I've tried the various pre-builts on the pdcurses website. No such luck.
I of course resorted to building from source. Using nmake from the Visual Studio command prompt as prescribed. Built ok. Nada on link.
What am I missing. It's maybe just too late on Friday...
Output below:
1>------ Build started: Project: test, Configuration: Debug x64 ------
1>Build started 14/12/2012 16:24:32.
1>InitializeBuildStatus:
1> Touching "x64\Debug\test.unsuccessfulbuild".
1>ClCompile:
1> main.c
1>C:\dep\pdcurses\curses.h(160): warning C4005: 'MOUSE_MOVED' : macro redefinition
1> C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\wincon.h(101) : see previous definition of 'MOUSE_MOVED'
1>main.c(73): warning C4133: 'function' : incompatible types - from 'unsigned short [20]' to 'const char *'
1>ManifestResourceCompile:
1> All outputs are up-to-date.
1>main.obj : error LNK2019: unresolved external symbol endwin referenced in function main
1>main.obj : error LNK2019: unresolved external symbol wgetch referenced in function main
1>main.obj : error LNK2001: unresolved external symbol __imp_stdscr
1>main.obj : error LNK2019: unresolved external symbol refresh referenced in function main
1>main.obj : error LNK2019: unresolved external symbol printw referenced in function main
1>main.obj : error LNK2019: unresolved external symbol initscr referenced in function main
1>C:\proj\test.exe : fatal error LNK1120: 6 unresolved externals
1>
1>Build FAILED.
1>
1>Time Elapsed 00:00:01.47

Ok. I feel rather stupid. Here is the solution for posterity...
The distributed pdcurses binaries are 32bit. I was trying to build for 64bit.
Fundamentally, I forgot the first rule of linkage: don't mix and match architectures.
More specifically, when attempting to then build from source:
1) beware of starting the wrong Visual Studio command prompt. The default one from the Tools menu is the x86 one. If you just try and run cl.exe you'll find this out.
Instead, run the prompt from the start menu: Microsoft Visual Studio 2010->Visual Studio Tools->Visual Studio x64 Win64 Command Prompt (2010)
Invoke the build then by cd'ing to pdcurses directory/win32a and typing:
nmake -f vcwin32.mak DLL=pdcurses.dll
Also, 2) before you compile pdcurse change line 111 of the pdcurses Windows makefile (vcwin32.mak):
cvtres /MACHINE:X64 /NOLOGO /OUT:pdcurses.obj pdcurses.res
(NOTE: i.e. X64 architecture!)
Everything is now consistent. The pdcurses library will build. And it will link with my test app which (as the original output shows) I am building on x64.

Related

Visual Studio Building static lib gets unresolved external symbol

I am statically building LibSSH on Windows and managed to build it with cmake-gui. If I build the resulting Visual Studio project, I get the ssh.lib file. However, if I link this .lib file to another project where I need it, I receive following errors:
Severity Code Description Project File Line Suppression State
Error LNK2019 unresolved external symbol _BN_bn2hex referenced in function _ssh_print_bignum Project1 C:\Users\User\Desktop\Project1\Project1\ssh.lib(bignum.obj) 1
Error LNK2019 unresolved external symbol _DH_new referenced in function _ssh_dh_set_parameters Project1 C:\Users\User\Desktop\Project1\Project1\ssh.lib(dh_crypto.obj) 1
Error LNK2019 unresolved external symbol _DH_free referenced in function _ssh_dh_cleanup Project1 C:\Users\User\Desktop\Project1\Project1\ssh.lib(dh_crypto.obj) 1
And like ~250 more of these.
I found these object files on my system in another directory of the LibSSH project, but don't know what to do with these.
Can anybody help me with this problem?

Windows SDK issue linking 64-bit exe on Windows 7

I have an exe written in C (not C++ or C#) to call a dll. It compiles with Clang and I'm linking it from the Visual Studio command line using link.exe. This build is on Windows 7. My command string is:
link.exe SxSv.obj /nologo /subsystem:console /MACHINE:X64 /LIBPATH:"C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Lib\x64\" /OUT:SxSv.exe kernel32.lib
Link.exe gives me these errors:
SxSv.obj : error LNK2019: unresolved external symbol __imp_LoadLibraryA referenced in function WinMain
SxSv.obj : error LNK2019: unresolved external symbol __imp_GetProcAddress referenced in function WinMain
SxSv.obj : error LNK2019: unresolved external symbol __imp_FreeLibrary referenced in function WinMain
SxSv.obj : error LNK2019: unresolved external symbol __stdio_common_vsprintf referenced in function _vsnprintf_l
LINK : error LNK2001: unresolved external symbol mainCRTStartup
C:\Program Files (x86)\Windows Kits\10\lib\10.0.17763.0\um\x86\uuid.lib : warning LNK4272: library machine type 'x86' conflicts with target machine type 'x64'
SxSv.exe : fatal error LNK1120: 5 unresolved externals
The problem seems to be this line:
/LIBPATH:"C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Lib\x64\"
and I think the problem is the Windows SDK that is installed. This computer has Visual Studio 2017 CE installed.
My questions are:
It looks like there is only one SDK for Windows 7, released in 2010. Where would I expect to see it if it is installed?
Can I use it to link a 64-bit exe?
3, There are a lot of uuid.lib files installed on this Windows 7 box. Which one would I use for Windows 7 for a 64-bit exe?⌈
I am doing this from the Visual Studio Developer command line, not from the IDE.
Thanks for any help.
EDIT: the question suggested as the duplicate of this one is very helpful but it's not the complete solution to this problem as it does not explain what libraries to link to. The comment below by Hans Passant helps best. First I will transfer this project to Visual Studio and go from there to find the right libraries to link this to.

Undefined symbols building MQTT Paho on Windows

I'm trying to build paho_mqtt.c on Windows X86 (64-bit). I'm using Visual Studio Community 2013. Its a supported configuration.
To build paho_mqtt.c for 64-bit, one needs OpenSSL compiled for Windows 64-bit. To build OpenSSL I found I needed a new version of Active Perl. I then used the following commands to build OpenSSL:
perl Configure -no-asm VC-WIN64A
nmake
nmake test
All the tests worked so I have believe I have working SSL/TLS libraries.
When building MQTT paho it couldn't find the ssl.h. I used the trick on this page listed below to set the environment variables so msbuild would get the include path from the environment variables:
Adding additional library and include paths when compiling from command line
That worked and paho found ssl.h.
Next msbuild of paho.mqtt.c could not find libeay32 / ssleay32.dll. First I used the trick from above again so msbuild would search the correct directory for the openssl libraries. Although the new libraries work, the library names are different. I used the information in 2) on Compiling OpenSSL for Windows, Linux, and Macintosh and I did the following:
cp libssl.lib libeay32.lib
cp libcrypto.lib ssleay32.lib
This is questionable I know, but it appears to have worked; that is, the link command that was failing now runs without warning or error. But it might have just deferred any unresolved symbol problems until later.
msbuild is failing later when trying to link an executable (shown at the bottom of this post). msbuild is complaining it cannot resolve the MQTTClient_* funcitons/symbols (e.g. MQTTClient_connect). Those functions are all in MQTTClient.c, and msbuild built MQTTClient.obj without emitting any errors.
My questions revolve around "what is the real problem?":
Is the problem with MQTTClient.obj:
maybe it is not included in the link command?
or maybe the symbols are not in the object file?
Is the problem that I renamed the libraries?
msbuild is not reporting that it cannot find the MQTTClient.obj.
If the problem is with the openssl libraries I expect it would report some openssl symbols are not found.
On linux I would use nm -g to see whether the undefined symbols are in the MQTT_Client.obj. How do I verify this in Windows?
Thanks for any help you can provide,
Link:
C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\BIN\amd64\link.exe /ERRORREPORT:QUEUE /OUT:"C:\Users\don\paho.mqtt.c\Windows Build\x64\Release\paho-cs-pub.exe" /INCREMENTAL:NO /NOLOGO /LIBPA
TH:"C:\Users\don\paho.mqtt.c\Windows Build\\x64\Release" "paho-mqtt3a.lib" kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc3
2.lib odbccp32.lib /MANIFEST /MANIFESTUAC:"level='asInvoker' uiAccess='false'" /manifest:embed /DEBUG /PDB:"C:\Users\don\paho.mqtt.c\Windows Build\x64\Release\paho-cs-pub.pdb" /SUBSYSTEM:CONSOLE /O
PT:REF /OPT:ICF /LTCG /TLBID:1 /DYNAMICBASE /NXCOMPAT /IMPLIB:"C:\Users\don\paho.mqtt.c\Windows Build\x64\Release\paho-cs-pub.lib" /MACHINE:X64 x64\Release\paho_cs_pub.obj
paho_cs_pub.obj : error LNK2001: unresolved external symbol MQTTClient_create [C:\Users\don\paho.mqtt.c\Windows Build\stdoutsuba\stdoutsuba.vcxproj]
paho_cs_pub.obj : error LNK2001: unresolved external symbol MQTTClient_yield [C:\Users\don\paho.mqtt.c\Windows Build\stdoutsuba\stdoutsuba.vcxproj]
paho_cs_pub.obj : error LNK2001: unresolved external symbol MQTTClient_setCallbacks [C:\Users\don\paho.mqtt.c\Windows Build\stdoutsuba\stdoutsuba.vcxproj]
paho_cs_pub.obj : error LNK2001: unresolved external symbol MQTTClient_disconnect [C:\Users\don\paho.mqtt.c\Windows Build\stdoutsuba\stdoutsuba.vcxproj]
paho_cs_pub.obj : error LNK2001: unresolved external symbol MQTTClient_publish [C:\Users\don\paho.mqtt.c\Windows Build\stdoutsuba\stdoutsuba.vcxproj]
paho_cs_pub.obj : error LNK2001: unresolved external symbol MQTTClient_destroy [C:\Users\don\paho.mqtt.c\Windows Build\stdoutsuba\stdoutsuba.vcxproj]
paho_cs_pub.obj : error LNK2001: unresolved external symbol MQTTClient_connect [C:\Users\don\paho.mqtt.c\Windows Build\stdoutsuba\stdoutsuba.vcxproj]
C:\Users\don\paho.mqtt.c\Windows Build\x64\Release\paho-cs-pub.exe : fatal error LNK1120: 7 unresolved externals [C:\Users\don\paho.mqtt.c\Windows Build\stdoutsuba\stdoutsuba.vcxproj]

C - Unable to use MSVC linker to link .obj files from the command line

I have been trying to follow the instructions at http://llvm.org/docs/GettingStartedVS.html#an-example-using-the-llvm-tool-chain, but I run into errors at the linking stage. For some reason, I can compile the "hello world" program all the way to an .exe inside the Visual Studio GUI, but when I run the compiler (either clang or cl) from the command line, I get strange errors. I can create .obj objects just fine, but linking produces errors like the following:
link /DEFAULTLIB:libcmt /VERBOSE hello.obj
Microsoft (R) Incremental Linker Version 12.00.31101.0
Copyright (C) Microsoft Corporation. All rights reserved.
Starting pass 1
Searching libraries
Searching C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\LIB\libcmt.lib:
Finished searching libraries
Finished pass 1
Unused libraries:
C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\LIB\libcmt.lib
hello.obj : error LNK2019: unresolved external symbol printf referenced in function main
LINK : error LNK2001: unresolved external symbol mainCRTStartup
hello.exe : fatal error LNK1120: 2 unresolved externals
For some reason, it is ignoring the specified library and is unable to locate the relevant libraries for linking. How can I get the linker to resolve the symbols properly?

LINK : error LNK2001: unresolved external symbol NtProcessStartup

I am new to Windows driver development and minifilters and I am trying to build the nullFilter sample using command line tools.
So I added #pragma comment(lib, "FltMgr.lib") to the .c file and issued the following commands successfully:
cl.exe /nologo /Fo../../bin\filter.obj /c filter.c /D _AMD64_
rc.exe /nologo /Fo../../bin\filter.res filter.rc
However, when I try to create the sys file:
link.exe /nologo /DRIVER:WDM /out:../../bin\filter.sys ../../bin\filter.obj ../../bin\filter.res
LINK : error LNK2001: unresolved external symbol NtProcessStartup
../../bin\filter.sys : fatal error LNK1120: 1 unresolved externals
I am using VS2012 Express and WDM8. My LIB environment variable is:
C:\Program Files (x86)\Windows Kits\8.0\Lib\win8\um\x64;C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\lib\amd64;C:\Program Files (x86)\Windows Kits\8.0\Lib\win8\km\x64;
What am I doing wrong? Am I missing something?
NtProcessStartup function is to driver development what 'main' is for regular C programs. In other words, it is the program entry function that you need to provide yourself. See the article here for an introduction and explanation of this function. You can overrule the name of the startup function by using the -entry linker option. Setting '-entry:DriverEntry' is a common practice for driver development.

Resources