QT 5 QPrinter linq error - qt5

I use QT 5.1.1 and Qt Creator 2.8.1
I want use printer:
QPrinter printer(QPrinter::HighResolution);
QPrintDialog printdialog(&printer,this);
if (printdialog.exec() == QDialog::Accepted)
{
QTextDocument doc;
doc.setHtml(s);
doc.print(&printer);
}
And I get this error:
DictionaryWidget.obj:-1: error: LNK2019: unresolved external symbol "__declspec(dllimport) public: _thiscall QPrinter::QPrinter(enum QPrinter::PrinterMode)" (_imp_??0QPrinter##QAE#W4PrinterMode#0##Z) referenced in function "private: void __thiscall DictionaryWidget::on_pbPrint_clicked(void)" (?on_pbPrint_clicked#DictionaryWidget##AAEXXZ)
in .pro file I have:
QT += core gui xml printsupport
to build Environment in QT Creator LIBPATH as follows:
libpath: C:\Windows\Microsoft.NET\Framework64\v4.0.30319;C:\Windows\Microsoft.NET\Framewo‌​rk64\v3.5;C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\LIB\amd64;C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\ATLMFC\LIB\amd64;C:\Program Files (x86)\Windows Kits\8.0\References\CommonConfiguration\Neutral;C:\Program Files (x86)\Microsoft SDKs\Windows\v8.0\ExtensionSDKs\Microsoft.VCLibs\11.0\References\CommonConfigura‌​tion\neutral;C:\Qt\5.1.1\msvc2012\lib;
In the folder C:\Qt\5.1.1\msvc2012\lib file is located Qt5PrintSupport.lib
What should I do to make the project work?

Related

Link errors when using CMake and VCPKG with GoogleTest

As a bit of background, I have a project that I have been developing with Visual Studio and VCPKG manifest mode for some time, it contains one static library project and one unit test project. Everything has been working correctly. I'm now trying to migrate this solution to use CMake, this is my first time using CMake.
With CMake the VCPKG dependencies install correctly, and both the static library and unit tests compile, however it fails on the linking step with a large number of linker errors all related to the GoogleTest library. Here is the first, as an example:
CppSlippiTest.obj : error LNK2019: unresolved external symbol "class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __cdecl testing::internal::FormatMatcherDescription(bool,char const *,class std::vector<char const*,class std::allocator<char const *> > const &,class std::vector<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,class std::allocator<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > > > const &)" (?FormatMatcherDescription#internal#testing##YA?AV$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std##_NPEBDAEBV?$vector#PEBDV$allocator#PEBD#std###4#AEBV?$vector#V?$basic_string#DU?$char_traits#D#std##V$allocator#D#2##std##V?$allocator#V?$basic_string#DU$char_traits#D#std##V?$allocator#D#2##std###2##4##Z) referenced in function "private: class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __cdecl cpp_slippi::MatchOptionalMatcherP2<class testing::internal::Eq2Matcher,class std::optional<unsigned char> >::gmock_Impl<class std::optional<unsigned char> const &>::FormatDescription(bool)const " (?FormatDescription#$gmock_Impl#AEBV?$optional#E#std###$MatchOptionalMatcherP2#VEq2Matcher#internal#testing##V?$optional#E#std###cpp_slippi##AEBA?AV?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std##_N#Z) [C:\Users\Derek\Projects\CppSlippi\build\Test.vcxproj]
There are 36 more of these.
Here is my CMakeLists.txt, slightly abridged for clarity:
cmake_minimum_required(VERSION 3.12...3.24)
# Must be before project()
set(VCPKG_TARGET_TRIPLET x64-windows-static)
project(CppSlippi
VERSION 1.0
DESCRIPTION "Slippi replay file parsing library for C++."
LANGUAGES CXX)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
find_package(GTest CONFIG REQUIRED)
find_package(nlohmann_json CONFIG REQUIRED)
add_library(CppSlippi STATIC
CppSlippi/src/CppSlippi.cpp
CppSlippi/src/CppSlippi.h
...)
target_include_directories(CppSlippi PUBLIC CppSlippi/src)
target_compile_features(CppSlippi PUBLIC cxx_std_20)
target_compile_options(CppSlippi PUBLIC /MTd)
set_target_properties(CppSlippi PROPERTIES CXX_EXTENSIONS OFF)
target_link_libraries(CppSlippi PUBLIC nlohmann_json::nlohmann_json)
if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
include(CTest)
include(GoogleTest)
endif()
if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME AND BUILD_TESTING)
add_executable(Test
Test/src/CppSlippiTest.cpp
...)
target_include_directories(Test PUBLIC Test/src)
target_compile_features(Test PUBLIC cxx_std_20)
target_compile_options(Test PRIVATE /bigobj /MTd)
set_target_properties(Test PROPERTIES CXX_EXTENSIONS OFF)
target_link_libraries(Test PUBLIC
CppSlippi
nlohmann_json::nlohmann_json
GTest::gtest_main)
gtest_discover_tests(Test)
endif()
Here is my VCPKG manifest:
{
"$schema": "https://raw.githubusercontent.com/microsoft/vcpkg/master/scripts/vcpkg.schema.json",
"name": "cpp-slippi",
"version": "1.0.0",
"description": "C++ Slippi replay parser.",
"builtin-baseline": "68b7fec22eb5fd9c0236b1e42b3c0deb8e771b37",
"dependencies": [
"gtest",
"nlohmann-json"
],
"supports": "windows"
}
And to build this I am running:
cmake --build build --target Test
I turned on --verbose to get more information, and this is the link command that CMake is running:
Link:
C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.34.31933\bin\HostX64\x64\link.exe /ERRORREPO
RT:QUEUE /OUT:"C:\Users\Derek\Projects\CppSlippi\build\Debug\Test.exe" /INCREMENTAL /ILK:"Test.dir\Debug\Test.ilk" /N
OLOGO /NATVIS:"C:\Users\Derek\Projects\CppSlippi\build\vcpkg_installed\x64-windows-static\share\nlohmann_json\nlohman
n_json.natvis" Debug\CppSlippi.lib "vcpkg_installed\x64-windows-static\debug\lib\manual-link\gtest_main.lib" "vcpkg_i
nstalled\x64-windows-static\debug\lib\gtest.lib" kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib
oleaut32.lib uuid.lib comdlg32.lib advapi32.lib /MANIFEST /MANIFESTUAC:"level='asInvoker' uiAccess='false'" /manifes
t:embed /DEBUG /PDB:"C:/Users/Derek/Projects/CppSlippi/build/Debug/Test.pdb" /SUBSYSTEM:CONSOLE /TLBID:1 /DYNAMICBASE
/NXCOMPAT /IMPLIB:"C:/Users/Derek/Projects/CppSlippi/build/Debug/Test.lib" /MACHINE:X64 /machine:x64 Test.dir\Debug
\CppSlippiTest.obj ...
Note the presence of gtest_main.lib and gtest.lib, these are the libraries that I believe should include the missing functions. I have checked that these files are present at the locations shown.
I know that in Visual Studio using the GoogleTest main requires adding an AdditionalDependency manually, but from all the instructions I can find this should not be necessary in CMake and the .lib is already in the command line. I did try using target_link_directories anyways, but this did not help.
At this point I am baffled and searching on Google and Stack Overflow has failed to turn up any help.
You link only one of 4 GoogleTest libraries to your app
target_link_libraries(Test PUBLIC
CppSlippi
nlohmann_json::nlohmann_json
GTest::gtest_main)
Depending on the application needs, it should be linked to at least one more library
target_link_libraries(Test PUBLIC
CppSlippi
nlohmann_json::nlohmann_json
GTest::gtest_main
GTest::gtest)
Or
target_link_libraries(Test PUBLIC
CppSlippi
nlohmann_json::nlohmann_json
GTest::gmock_main
GTest::gmock
GTest::gtest)

WinUI3/Desktop/C++: Can't compile winrt::resume_foreground(Microsoft::System::DispatcherQueue const& dispatcher)

I want to use:
co_await winrt::resume_foreground(window.DispatcherQueue());
(Type of "window" is: "winrt::Microsoft::UI::Xaml::Window")
But I cannot compile it because
winrt::resume_foreground(Microsoft::System::DispatcherQueue const& dispatcher)
is not defined.
I cannot include #include <winrt/Microsoft.System.h> which contains the DispatcherQueue class.
My environment:
Windows 10 Pro, 21H1, 19043.1083
Visual Studio Community 2019 (16.10.3)
Visual Studio Extension: Project Reunion Version 0.8.0.46122163
Project Template: C++, Blank App, Packaged (WinUI 3 in Desktop)
To reproduce the error I used the Project Template above and added the following method to the "App" class.
App.xaml.h
winrt::Windows::Foundation::IAsyncAction foo();
App.xaml.cpp
winrt::Windows::Foundation::IAsyncAction App::foo()
{
co_await winrt::resume_foreground(window.DispatcherQueue());
}
I get the error message:
D:\Solution\WinUi3 Test\WinUi3 Test\App.xaml.cpp(50,21): error C2039: 'resume_foreground': is not a member of 'winrt'
1>D:\Solution\WinUi3 Test\WinUi3 Test\MainWindow.xaml.h(23): message : see declaration of 'winrt'
1>D:\Solution\WinUi3 Test\WinUi3 Test\App.xaml.cpp(50,38): error C3861: 'resume_foreground': identifier not found
1>Done building project "WinUi3 Test.vcxproj" -- FAILED.
If I try to include #include <winrt/Microsoft.System.h> I get:
1>D:\Solution\WinUi3 Test\WinUi3 Test\pch.h(25,10): fatal error C1083: Cannot open include file: 'winrt/Microsoft.System.h': No such file or directory
1>Done building project "WinUi3 Test.vcxproj" -- FAILED.
If I include #include <winrt/Windows.System.h> and #include <winrt/Windows.UI.Core.h> I get:
1>D:\Solution\WinUi3 Test\WinUi3 Test\App.xaml.cpp(50,63): error C2665: 'winrt::resume_foreground': none of the 2 overloads could convert all the argument types
1>D:\Solution\WinUi3 Test\WinUi3 Test\Generated Files\winrt\Windows.UI.Core.h(2805,31): message : could be 'winrt::resume_foreground::awaitable winrt::resume_foreground(const winrt::Windows::UI::Core::CoreDispatcher &,const winrt::Windows::UI::Core::CoreDispatcherPriority) noexcept' (compiling source file App.xaml.cpp)
1>D:\Solution\WinUi3 Test\WinUi3 Test\Generated Files\winrt\Windows.System.h(4529,31): message : or 'winrt::resume_foreground::awaitable winrt::resume_foreground(const winrt::Windows::System::DispatcherQueue &,const winrt::Windows::System::DispatcherQueuePriority) noexcept' (compiling source file App.xaml.cpp)
1>D:\Solution\WinUi3 Test\WinUi3 Test\App.xaml.cpp(50,63): message : while trying to match the argument list '(winrt::Microsoft::UI::Dispatching::DispatcherQueue)'
1>Done building project "WinUi3 Test.vcxproj" -- FAILED.
Include
#include <winrt/Microsoft.UI.Dispatching.h>
#include <Microsoft.UI.Dispatching.co_await.h>
When updating from 0.8.0 preview to 0.8.0 there was a namespace change from
Microsoft.System to Microsoft.UI.Dispatching and resume_foreground is now defined in Microsoft.UI.Dispatching.co_await.h.
The answer from Markus does not work for me in the WinUI3 1.0 release because the Microsoft.UI.Dispatching.co_await.h header file does not exist. However, the following does work:
#include <wil/cppwinrt.h>
#include <wil/cppwinrt_helpers.h>
co_await wil::resume_foreground(DispatcherQueue());

Mono Tesseract 3 ddlmap can't map liblept172.so

I want to use tesseract 3 nuget package with mono. I have a dll not found error at runtime : System.DllNotFoundException : Failed to find library liblept172.so for platform x64.
I tried to add a config file in the same folder of dll , and in et/mono/config too.
<dllmap dll="liblept172.dll" target="/usr/lib/liblept.so"/>
I tried rename dll in liblept.dll.
I added /usr/lib to ldconfig and i linked liblept172.so to liblept.so with no result. Is someone using tesseract 3 with mono (archlinux) ?
using System;
using Tesseract;
using System.Drawing;
namespace tesstessarct
{
class MainClass
{
public static void Main (string[] args)
{
using (TesseractEngine engine = new TesseractEngine (#"/usr/share/tessdata", "fra", EngineMode.TesseractOnly, "config"))
{
engine.SetVariable("tessedit_char_whitelist", "0123456789");
var page = engine.Process (new Bitmap("/test.jpg"));
Console.Write (page.GetText ());
}
}
}
}
The Tesseract Nuget :
<package id="Tesseract" version="3.0.2.0" targetFramework="net45" />
Is only the .Net/Mono wrapper. You will also need the language files and the native shared libraries built for ArchLinux
Build from Source: https://github.com/tesseract-ocr/tesseract
Install from package: https://www.archlinux.org/packages/community/i686/tesseract/

Linking to a static lib compiled with MSVC

I'm trying to link with a simple C lib on windows against Rust library
My lib is .h
extern "C" {
void say_hello(const char* s);
}
.cpp
#include <stdio.h>
void say_hello(const char* s) {
printf("hello world");
}
My Rust file
#[link(name="CDbax", kind="static")]
extern "C" {
fn say_hello(s: *const libc::c_char) -> () ;
}
Linking fails by giving an error with one of the data symbols
error: linking with `gcc` failed: exit code: 1
note: "gcc" "-Wl,--enable-long-section-names" "-fno-use-linker-plugin" "-Wl,--nxcompat" "-Wl,--large-address-aware" "-shared-libgcc" "-L" "C:\Program Files (x86)\Rust 1.2\bin\rustlib\i686-pc-windows-gnu\lib" "e:\Rust\DBTools\DBAnalytics\target\debug\DBAnalytics.o" "-o" "e:\Rust\DBTools\DBAnalytics\target\debug\DBAnalytics.dll" "e:\Rust\DBTools\DBAnalytics\target\debug\DBAnalytics.metadata.o" "C:\Program Files (x86)\Rust 1.2\bin\rustlib\i686-pc-windows-gnu\lib\libstd-11582ce5.rlib" "C:\Program Files (x86)\Rust 1.2\bin\rustlib\i686-pc-windows-gnu\lib\libcollections-11582ce5.rlib" "C:\Program Files (x86)\Rust 1.2\bin\rustlib\i686-pc-windows-gnu\lib\librustc_unicode-11582ce5.rlib" "C:\Program Files (x86)\Rust 1.2\bin\rustlib\i686-pc-windows-gnu\lib\librand-11582ce5.rlib" "C:\Program Files (x86)\Rust 1.2\bin\rustlib\i686-pc-windows-gnu\lib\liballoc-11582ce5.rlib" "C:\Program Files (x86)\Rust 1.2\bin\rustlib\i686-pc-windows-gnu\lib\liblibc-11582ce5.rlib" "C:\Program Files (x86)\Rust 1.2\bin\rustlib\i686-pc-windows-gnu\lib\libcore-11582ce5.rlib" "-L" "e:\Rust\DBTools\DBAnalytics\target\debug" "-L" "e:\Rust\DBTools\DBAnalytics\target\debug\deps" "-L" "C:\Program Files (x86)\Rust 1.2\bin\rustlib\i686-pc-windows-gnu\lib" "-L" "e:\Rust\DBTools\DBAnalytics\.rust\bin\i686-pc-windows-gnu" "-L" "e:\Rust\DBTools\DBAnalytics\bin\i686-pc-windows-gnu" "-Wl,-Bstatic" "-Wl,--whole-archive" "-l" "CDbax" "-Wl,--no-whole-archive" "-Wl,-Bdynamic" "-l" "ws2_32" "-l" "userenv" "-l" "advapi32" "-shared" "-l" "compiler-rt"
note: Warning: corrupt .drectve at end of def file
Cannot export ??_C#_0M#LACCCNMM#hello?5world?$AA#: symbol not found
The library is build on MSVC2013 as a simple static lib. The string "hello world" is in the data section, so I wouldn't expect it to cause a link error. Are there some specific settings I need to be aware about when linking with C libraries on windows?
Btw it's 32bit MSVC lib.
Ok, a few things. First of all, there's no such thing as a "static DLL": a DLL is a dynamically linked library.
Secondly, Rust uses the MinGW toolchain and runtime. Mixing MSVC and MinGW runtimes can cause odd things to happen, so it's probably best avoided if at all possible. Rust has only recently landed very early support for building using the MSVC runtime.
However, you can get this specific example to work, apparently without any ill effects. You just need to change a few things:
You need to use a dynamic library; my understanding is that this makes bad interactions a little less likely.
You need to actually compile say_hello with C linkage, not C++ linkage. You did this in the header, but not in the source file.
You need to publicly export say_hello from the library.
Thus:
hello.rs:
#[link(name="hello", kind="dylib")]
extern {
fn say_hello();
}
fn main() {
unsafe { say_hello(); }
}
hello.h:
#ifndef HELLO_H
#define HELLO_H
extern "C" {
__declspec(dllexport) void say_hello();
}
#endif
hello.cpp:
#include <cstdio>
#include "hello.h"
void say_hello() {
printf("hello world\n");
}
build.cmd
cl /LD hello.cpp
rustc -L. hello.rs
On my machine, this produces hello.exe and hello.dll; when run, hello.exe prints out hello world.

OpenCV highgui110.dll Link Error

i encounter an error like
Error 1 fatal error LNK1107: invalid or corrupt file: cannot read at 0x2C8 C:\Program Files\OpenCV\bin\highgui110.dll
Additional Include Directories
C:\Program Files\OpenCV\cxcore\include
C:\Program Files\OpenCV\otherlibs\highgui
C:\Program Files\OpenCV\cv\include
Additional Library Directories
C:\Program Files\OpenCV\otherlibs
C:\Program Files\OpenCV\lib
C:\Program Files\OpenCV\bin
Additional Dependencies
cv.lib
highgui.lib
cxcore.lib
highgui110.dll
Error Message is
Error 1 fatal error LNK1107: invalid or corrupt file: cannot read at 0x2C8 C:\Program Files\OpenCV\bin\highgui110.dll 1 OpenCV Capture
What wrong with highgui.dll ?
Please help.
Thanks.
This is my source code.
Code:
#ifndef CAM_CAPTURE_H
#define CAM_CAPTURE_H
#include "cv.h"
#include "highgui.h"
class CamCapture
{
private:
CvCapture* myCaptureHandler;
IplImage* videoFrame;
int key;
public:
CamCapture();
~CamCapture();
void Init();
};
#endif
Remove highgui110.dll from your list of Additional dependencies. In additional dependencies you should list only lib files.