Add dependency on Shell32.lib to WDK makefile - c++

I've successfully powered my way through the WDK XPSDrv sample project and modified it to do what I need. However, I absolutely cannot figure out how to get the build scripts to reference/include/whatever shell32.lib. I'm a .NET guy! This is strange and terrifying territory.
I think adding a dependency reference is what I need to do. When I compile I get this error
3>errors in directory c:\winddk\7600.16385.1\src\printgit\xpsdrvsmpl\
src\filters\common
3>c:\winddk\7600.16385.1\src\printgit\xpsdrvsmpl\src\filters\common\
xdstrmflt.cpp(238) : error C3861: 'ShellExecute': identifier not found
Due to my extreme lack of knowledge (and hurry) I'm not using visual studio, just simple mods in notepad++ and the shell wdk build environment. I have a surrogate project in VS where I've been writing and testing small chunks of code. In that project I added a Dependency library to shell32.lib and everything worked perfectly.
There's a makefile that references a sources, the contents are below.
Not that it matters, but the code that requires shell32 is
HINSTANCE statu = ShellExecute(NULL,TEXT("open"),szTempFileName,NULL,NULL,9);
Here's the sources file.
INCLUDES=$(INCLUDES); \
.\; \
.\..\inc; \
.\..\debug; \
$(DDK_INC_PATH); \
$(SDK_INC_PATH)\gdiplus; \
USE_ATL=1
USE_STL=1
ATL_VER=70
STL_VER=70
# We use STL 7.0, which is not available pre-Vista. We therefore set USE_LIBCMT=1
# If STL 7.0 is not necessary, USE_MSVCRT=1 is recommended
USE_LIBCMT=1
USE_IDLBASED_DLLDATA=1
USE_OBJECT_ROOT=1
MSC_WARNING_LEVEL=/W4 /WX
USE_NATIVE_EH=1
PRECOMPILED_CXX=1
PRECOMPILED_INCLUDE=precomp.h
# To remove debug code remove -DDBG from the line below
C_DEFINES=$(C_DEFINES) -D_UNICODE -DUNICODE
SOURCES=\
bkpchndlr.cpp \
bkpthndlr.cpp \
bkschema.cpp \
cmpthndlr.cpp \
cmprofpthndlr.cpp \
cmprofpchndlr.cpp \
cmintpthndlr.cpp \
cmschema.cpp \
cmprofileschema.cpp \
cmintentsschema.cpp \
globals.cpp \
nupschema.cpp \
nupchndlr.cpp \
nupthndlr.cpp \
pchndlr.cpp \
pgscpchndlr.cpp \
pgscpthndlr.cpp \
pgscschema.cpp \
porientpthndlr.cpp \
porientschema.cpp \
psizepthndlr.cpp \
psizeschema.cpp \
pimagepthndlr.cpp \
pimageschema.cpp \
pshndlr.cpp \
pthndlr.cpp \
ptquerybld.cpp \
schema.cpp \
wmpchndlr.cpp \
wmpthndlr.cpp \
wmschema.cpp \
workbuff.cpp
TARGETNAME=xdsmplcmn
TARGETTYPE=LIBRARY

For example in your sources file:
TARGETLIBS=$(SDK_LIB_PATH)\kernel32.lib $(SDK_LIB_PATH)\user32.lib $(SDK_LIB_PATH)\shell32.lib
... amend as needed ;)
However, your error is actually not a linker error but a compiler error, so you'll likely want to include the header that declares ShellExecute, which is shellapi.h, in some way.
Just looked the sample up in my WDK (7600.16385.1) and as a matter of fact you removed the very important part reproduced below, to which you just would have to append the other .lib files to link against:
TARGETLIBS= \
$(SDK_LIB_PATH)\kernel32.lib \
$(SDK_LIB_PATH)\user32.lib \
$(SDK_LIB_PATH)\winspool.lib \
$(SDK_LIB_PATH)\ole32.lib \
$(SDK_LIB_PATH)\oleaut32.lib \
$(SDK_LIB_PATH)\advapi32.lib \
$(SDK_LIB_PATH)\msxml6.lib \
$(SDK_LIB_PATH)\uuid.lib \
$(SDK_LIB_PATH)\Comdlg32.lib \
$(OBJ_PATH)\..\debug\$O\xdsdbg.lib \
$(OBJ_PATH)\..\common\$O\xdsmplcmn.lib \
... apologies, there are plenty of sources files as part of this sample, so of course I cannot really know which of the samples you modified and are trying to build :)

Related

Cannot build cc-tools with Boost 1.76 on macOS got 'cannot find the flags to link with Boost regex' error

I'm trying to build cc-tool debugger as described here https://www.zigbee2mqtt.io/information/flashing_the_cc2531.html
But at configure step got this error
checking for the Boost regex library... no
configure: error: cannot find the flags to link with Boost regex
Same issue described here https://github.com/dashesy/cc-tool/issues/25 and suggested solution is to downgrade boost to 1.60. But it does not work anymore because 1.60 deleted from brew.
I've tried to use clang compiler instead of gcc but it does not work too.
MacOS: Big sur 11.5.2 (20G95)
Here the solution:
CC=/usr/bin/clang \
CXX=/usr/bin/clang++ \
CPPFLAGS=-I/usr/local/include \
LDFLAGS=-I/usr/local/include \
./bootstrap
CC=/usr/bin/clang \
CXX=/usr/bin/clang++ \
CPPFLAGS=-I/usr/local/include \
CXXFLAGS="-std=c++0x" \
LDFLAGS="-I/usr/local/include -lboost_system" \
LIBUSB_CFLAGS=-I/usr/local/include/libusb-1.0 \
LIBUSB_LIBS="-L/usr/local/lib -lusb-1.0" \
./configure
It allows to configure with boost 1.76. Found here https://gist.github.com/kidpixo/ef1a26ae953e3939a4eebe1b6fd2f07c
For mac with M1 CPU, macOS Monterey (boost version 1.78.0):
CC=/usr/bin/clang \
CXX=/usr/bin/clang++ \
CPPFLAGS=-I/opt/homebrew/include \
LDFLAGS=-I/opt/homebrew/include \
./bootstrap
CC=/usr/bin/clang \
CXX=/usr/bin/clang++ \
CPPFLAGS=-I/opt/homebrew/include \
CXXFLAGS="-std=c++0x" \
LDFLAGS="-L/opt/homebrew/Cellar/boost/1.78.0_1/lib/" \
LIBUSB_CFLAGS=-I/opt/homebrew/include/libusb-1.0 \
LIBUSB_LIBS="-L/opt/homebrew/lib -lusb-1.0" \
./configure
I've hit the very same issue, right today (same OS: MacOS 11.5.2).
I think one solution would be to create your own tap, with the Formula copied from the removed boost#1.60 (Homebrew/homebrew-core#84434).

QT Creator undefined reference linker exit code 1, no vtable nor assembly

I have just been editing code for a proprietary software that has just been working fine. I will show some of the relevant code:
I've dealt with linker errors through QT before through a number of "Run qmake & rebuilds" however this time nothing seems to have changed with the program, yet every reference to a specific file is returning as undefined.
SOURCES += \
main.cpp \
mainwindow.cpp \
program.cpp \
dv.cpp \
s.cpp \
l.cpp \
n.cpp \
t.cpp \
t_c.cpp
HEADERS += \
mainwindow.h \
program.h \
dv.h \
s.h \
l.h \
n.h \
t.h \
tt.h \
t_c.h
FORMS += \
mainwindow.ui \
dv.ui \
s.ui \
l.ui \
n.ui \
t.ui \
testframe.ui \
t_c.ui
Class program.h includes nothing except the needed Q libraries (QMap, QString, etc)
Class t_c.h includes program.h.
Class t.h includes program.h, tt.h (which only includes Q libraries), and t_c.h
Class mainwindow.h includes program.h, dv.h, s.h, n.h, t.h
The latest addition was the creation of t_c.h and the adding of functions from program.h before it broke. I would think it would be an issue with t.h however every single reference to program.h's methods are "undefined", even in mainwindow.cpp
/usr/bin/ld: mainwindow.o: in function `MainWindow::MainWindow(QWidget*)':
mainwindow.cpp:(.text+0x121): undefined reference to `Program::method(QString)'
undefined reference to ... [all the way down]
I've tried cleaning, re-running qmake, deleting the build folder.
There are no external libraries outside of the Q Libraries. There is no "assembly_86_64" nor "vtable" related errors.
For some reason half of my functions cleared out after I condensed them in QT's view.
Alright.

How to resolve linker errors with Google protobuf from source using MSVC 2015/17 in Qt?

In our project, along with our own source files, we have included several protobuf source files directly. They compile fine with g++/clang++ in all the platforms and Mingw in Windows.
Since we want to use Qt WebEngine, the Mingw is not useful and hence we have to compile our code with MSVC only.
Now while compiling with MSVC (2015/17, 32/64 bit), it gives several linking errors of below nature:
error LNK2001: unresolved external symbol "public: virtual void __thiscall google::protobuf::Message::CheckTypeAndMergeFrom(class google::protobuf::MessageLite const &)" (?CheckTypeAndMergeFrom#Message#protobuf#google##UAEXABVMessageLite#23##Z)
error LNK2001: unresolved external symbol "public: static void __cdecl google::protobuf::internal::ReflectionOps::Merge(class google::protobuf::Message const &,class google::protobuf::Message *)" (?Merge#ReflectionOps#internal#protobuf#google##SAXABVMessage#34#PAV534##Z)
Question: How to fix all these linker errors?
For those who are interested, below are the set of protocol source files, which we include in the .pro file while compilation:
external/google/protobuf/any.cc \
external/google/protobuf/any.pb.cc \
external/google/protobuf/api.pb.cc \
external/google/protobuf/arena.cc \
external/google/protobuf/arenastring.cc \
external/google/protobuf/descriptor.cc \
external/google/protobuf/descriptor.pb.cc \
external/google/protobuf/descriptor_database.cc \
external/google/protobuf/dynamic_message.cc \
external/google/protobuf/duration.pb.cc \
external/google/protobuf/empty.pb.cc \
external/google/protobuf/extension_set.cc \
external/google/protobuf/extension_set_heavy.cc \
external/google/protobuf/field_mask.pb.cc \
external/google/protobuf/generated_message_reflection.cc \
external/google/protobuf/generated_message_util.cc \
external/google/protobuf/map_field.cc \
external/google/protobuf/message_lite.cc \
external/google/protobuf/reflection_ops.cc \
external/google/protobuf/repeated_field.cc \
external/google/protobuf/source_context.pb.cc \
external/google/protobuf/text_format.cc \
external/google/protobuf/type.pb.cc \
external/google/protobuf/unknown_field_set.cc \
external/google/protobuf/wire_format.cc \
external/google/protobuf/wire_format_lite.cc \
external/google/protobuf/wrappers.pb.cc \
external/google/protobuf/compiler/importer.cc \
external/google/protobuf/compiler/parser.cc \
external/google/protobuf/compiler/plugin.pb.cc \
external/google/protobuf/compiler/subprocess.cc \
external/google/protobuf/compiler/zip_writer.cc \
external/google/protobuf/io/coded_stream.cc \
external/google/protobuf/io/strtod.cc \
external/google/protobuf/io/tokenizer.cc \
external/google/protobuf/io/zero_copy_stream.cc \
external/google/protobuf/io/zero_copy_stream_impl.cc \
external/google/protobuf/io/zero_copy_stream_impl_lite.cc \
external/google/protobuf/message_.cc \
external/google/protobuf/stubs/atomicops_internals_x86_gcc.cc \
external/google/protobuf/stubs/bytestream.cc \
external/google/protobuf/stubs/common.cc \
external/google/protobuf/stubs/int128.cc \
external/google/protobuf/stubs/once.cc \
external/google/protobuf/stubs/status.cc \
external/google/protobuf/stubs/statusor.cc \
external/google/protobuf/stubs/stringpiece.cc \
external/google/protobuf/stubs/stringprintf.cc \
external/google/protobuf/stubs/structurally_valid.cc \
external/google/protobuf/stubs/strutil.cc \
external/google/protobuf/stubs/substitute.cc \
external/google/protobuf/stubs/time_.cc \
external/google/protobuf/util/type_resolver_util.cc \
external/google/protobuf/util/internal/datapiece.cc \
external/google/protobuf/util/internal/field_mask_utility.cc \
external/google/protobuf/util/internal/object_writer.cc \
external/google/protobuf/util/internal/proto_writer.cc \
external/google/protobuf/util/internal/protostream_objectsource.cc \
external/google/protobuf/util/internal/protostream_objectwriter.cc \
external/google/protobuf/util/internal/type_info.cc \
external/google/protobuf/util/internal/utility.cc
Here's a practical view of how I solved the problem, use the same methodology to solve yours.
Whether it is in your .pro file or directly in the qmake command, you provide a LIBS configuration variable (libraries to be linked to your project).
Here is an example : LIBS+=-L"c:/vcpkg/packages/openssl-windows_x64-windows/lib" -llibssl -llibcrypto
To enable this library, you need to provide the -l flags after the path. And as stated in the official documentation :
The library must exist for qmake to find the directory where a -l lib is located.
Which means for the example above that the following files have to exist :
C:/vcpkg/packages/openssl-windows_x64-windows/lib/libssl.lib
C:/vcpkg/packages/openssl-windows_x64-windows/lib/libcrypto.lib
Make sure they exist.

Qt: How can I add two different external library path?

I am trying to add two different external library path on Qt. So I put INCLUDEPATH and LIBS below to .pro file;
INCLUDEPATH += C:/SiliconSoftware/Runtime5.4.0/include \
C:/Basler/pylon4/pylon/include
LIBS += -L"C:\SiliconSoftware\Runtime5.4.0\lib\visualc" \
-lclsersis \
-ldisplay_lib \
-lfglib5 \
-lgbelib \
-liolibrt \
-lsiso_auxport \
-lsiso_genicam
LIBS += -L"C:\Basler\pylon4\pylon\lib\Win32" \
-lPylonUsb_MD_VC100_TL \
-lPylonUtility_MD_VC100 \
-lPylon1394_MD_VC100_TL \
-lPylonBase_MD_VC100 \
-lPylonBootstrapper \
-lPylonCLSer_MD_VC100_TL \
-lPylonGigE_MD_VC100_TL \
-lPylonGUI_MD_VC100
But I got this error;
C:\Users\GitekVision\Documents\Qt Projects\PylonSetUp\pylonsetup.h:4: error: >C1083: Cannot open include file: 'pylon/PylonIncludes.h': No such file or >directory.
I tried to take libraries one by one, it works. But together not working.
Anyone knows how to use 2 different external library on Qt project?

Qt with opencv exception handling error

I have been able to successfully integrate opencv with Qt using the following tutorial:
How to link opencv in QtCreator and use Qt library
However, When I try to write line #include "opencv/cv.h in my .cpp file, qt throws me an error:
D:\opencv\opencv_bin\install\include\opencv2\flann\saving.h:113: error: exception handling disabled, use -fexceptions to enable
throw FLANNException("Invalid index file, cannot read");
^
I am not sure if this is a qt problem or an opencv installation problem.
TEMPLATE = app
TARGET = cube4
QT += 3d
SOURCES = cubeview.cpp main.cpp \
haptics.cpp
HEADERS = cubeview.h \
haptics.h \
src/haptics.h \
src/adll.h \
src/afuncs.h \
src/atypes.h \
src/avars.h \
src/glut.h \
src/StdAfx.h \
hdl/hdl.h \
hdl/hdlConstants.h \
hdl/hdlErrors.h \
hdl/hdlExports.h \
hdlu/hdlu.h \
hdlu/hdluExports.h
HEADERS += \
Widget.h
RESOURCES = cube.qrc
win32:LIBS += -LD:\\opencv\\opencv_bin\\bin \
libopencv_core248d \
libopencv_highgui248d \
libopencv_imgproc248d \
libopencv_features2d248d \
libopencv_calib3d248d \
win32: INCLUDEPATH +="D:/opencv/opencv_bin/install/include"
Thanks iHarob. The solution was to add "exceptions" to the CONFIG variable in your project file (the *.pro file):
CONFIG += exceptions
This takes care of passing the correct compiler flags. The answer can be found here:
How to enable exception handling in mingw