C++ bit7z Unresolved External Symbol _imp_CharUpperW#4 - c++

I'm trying to use bit7z in my C++ code to create a program that zips a directory. I'm receiving a LNK2019 error for something called _imp_CharUpperW#4 in my bit7z_d.lib. My IDE is Visual Studio Community 2019 and I use C++ 20.
These are my files:
main.cpp
#include <QCoreApplication>
#include <string>
#include <iostream>
#include <filesystem>
#include <bit7z.hpp>
#include "main.h"
#include <bitcompressor.hpp>
namespace fs = std::filesystem;
using namespace bit7z;
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
std::string path = "C:/Users/aretz/Downloads/test";
for (const auto& entry : fs::directory_iterator(path))
std::cout << entry.path() << std::endl;
return a.exec();
}
void AIXLogger::CompressDir() {
Bit7zLibrary lib{ L"C:/Program Files/7-Zip/7z.dll" };
BitCompressor compressor{ lib, BitFormat::Zip };
vector< wstring > files = { L"C:/Users/aretz/Downloads/test" };
wstring zip = { L"output_archive.zip" };
compressor.compressFiles( files , zip );
}
void AIXLogger::Execute() {
CompressDir();
}
main.h
#pragma once
#include <qwidget.h>
#include <qobject.h>
#include <bit7z.hpp>
class AIXLogger : public QWidget
{
Q_OBJECT
public slots:
public:
void CompressDir();
void Execute();
};
aixLogger.pro
# ----------------------------------------------------
# This file is generated by the Qt Visual Studio Tools.
# ------------------------------------------------------
TEMPLATE = app
TARGET = aixLogger
DESTDIR = ./Debug
CONFIG += debug console
DEPENDPATH += .
MOC_DIR += .
OBJECTS_DIR += debug
UI_DIR += GeneratedFiles
RCC_DIR += GeneratedFiles
include(aixLogger.pri)
Screenshots of my Properties are here:
Additional Include Directories
Additional Library Directories
Additional Dependencies
This is the exact error:
Severity Code Description Project File Line Suppression State
Error LNK2019 unresolved external symbol __imp__CharUpperW#4 referenced in function "wchar_t __cdecl MyCharUpper(wchar_t)" (?MyCharUpper##YA_W_W#Z) aixLogger D:\local\aretz\Programmierung\git-workplace\aixLogger\bit7z_d.lib(MyString.obj) 1

Related

QT MSVC environment undefined Symbols and dllimport errors with self built libs

When building several 3rd party libraries from source I get undefined symbols build errors or dll import errors.
Im trying to work out why certain functions don't link/can't be linked.
I am using qt creator 7.0.0 qt.6.2.4 online installer linked to LLVM 14.0.0 (13.0.0 has a bug with /MANIFESTDEPENDENCY)
I have followed the below link to build libxml(build with multithreadeddll or MD runtime)
https://forum.unified-automation.com/viewtopic.php?t=26
as well as followed a similar link to build libxslt.
I link to them in the .pro
INCLUDEPATH += ../../../Thirdparty/msvclibxml/include
INCLUDEPATH += ../../../Thirdparty/msvclibxml/include/libxml2
win32:DEPENDPATH += -L../../../Thirdparty/msvclibxml/lib -llibxml2
win32:LIBS += -L../../../Thirdparty/msvclibxml/lib -llibxml2
I have run into similar issues with building BMX when linking to self contained expat library in the code.
I don't experience any issue with my self built libraries, the AWS c++ sdk, FFmpeg so my general method isn't wrong.
Any help would be greatly appreciated.
Upon request here's the use case of lib xml that fails
in the header
//extern "C"
{
#include <libxml/tree.h>
#include <libxml/xmlmemory.h>
#include <libxml/debugXML.h>
#include <libxml/HTMLtree.h>
#include <libxml/xmlIO.h>
#include <libxml/xinclude.h>
#include <libxml/catalog.h>
#include <libxml/parser.h>
#include <libxml/HTMLparser.h>
#include <libxslt/xslt.h>
#include <libxslt/xsltInternals.h>
#include <libxslt/transform.h>
#include <libxslt/xsltutils.h>
}
the called function.
int pdfWriter::generatePDFObject(QString stylesheetFileName, QString xmlFilePath, QString &pdfFileName, QTextDocument &document, QString &formattedString)
{
QFile fileCheck(xmlFilePath);
if (!fileCheck.open(QIODevice::ReadOnly))
{
qDebug() << "Xml file does not exist";
return 2;
}
fileCheck.close();
QFileInfo fileCheckInfo(xmlFilePath);
if (fileCheckInfo.suffix().compare("xml", Qt::CaseInsensitive) != 0)
{
qDebug() << "File does not have xml extension";
return 1;
}
//Put this in eFFData
QString styleSheetFileName;
QString styleSheetCustomerImage;
QString path = "C:/Users/User/hardcodedpathexample";
styleSheetFileName = path;
styleSheetFileName.append("/");
styleSheetFileName.append(stylesheetFileName);
styleSheetCustomerImage = path;
styleSheetCustomerImage.append("/");
styleSheetCustomerImage.append("hardecodedimagesfilenameexample");
// Code to create pdf file
pdfFileName = xmlFilePath;
pdfFileName.remove(".xml");
pdfFileName.append(".pdf");
xmlDocPtr doc, res;
xmlOutputBufferPtr buf = xmlAllocOutputBuffer(NULL);
doc = xmlParseFile(xmlFilePath.toUtf8());
const char *params[1];
params[0] = nullptr;
xsltStylesheetPtr cur = NULL;
xmlSubstituteEntitiesDefault(1);
xmlLoadExtDtdDefaultValue = 1;
cur = xsltParseStylesheetFile((const xmlChar *)styleSheetFileName.toLocal8Bit().data());
res = xsltApplyStylesheet(cur, doc, params);
xsltSaveResultTo(buf, res, cur);
xsltFreeStylesheet(cur);
xmlFreeDoc(res);
xmlFreeDoc(doc);
xsltCleanupGlobals();
xmlCleanupParser();
formattedString = QString::fromUtf8((char*)(xmlOutputBufferGetContent(buf)));
xmlOutputBufferClose(buf);
QPixmap pixmap;
pixmap = QPixmap(":/logo/e-logo.png");
document.addResource(QTextDocument::ImageResource, QUrl("image file name example"), pixmap.scaled(350, 100, Qt::KeepAspectRatio, Qt::SmoothTransformation));
QPixmap customerPixmap(styleSheetCustomerImage);
document.addResource(QTextDocument::ImageResource, QUrl("image file name example"), customerPixmap.scaled(350, 100, Qt::KeepAspectRatio, Qt::SmoothTransformation));
return 0;
}
multiple function fail - mainly xmlAllocOutputBuffer(Null) undefined symbol

Qt QGL includes not found

I have installed the last QT Creator, running a gived example code, but i get
error: 'QGLFormat' file not found and
error: 'QGLWidget' file not found
My pro file looks like
GLEW_PATH = ../ext/glew-1.9.0
GLM_PATH = ../ext/glm-0.9.4.1
TEMPLATE = app
TARGET = myfilename
LIBS += -Wl,-rpath $${GLEW_PATH}/lib -L$${GLEW_PATH}/lib
LIBS += -lGLEW -lGL -lGLU -lm
INCLUDEPATH += $${GLEW_PATH}/include $${GLM_PATH}
SOURCES = main.cpp viewer.cpp
HEADERS = viewer.h
CONFIG += qt opengl warn_on thread uic4 release
QT += core gui opengl xml widgets
The errors happen here in my only header viewer.h, but others includes look fine
// GLEW lib: needs to be included first!!
#include <GL/glew.h>
// OpenGL library
#include <GL/gl.h>
// OpenGL Utility library
#include <GL/glu.h>
// OpenGL Mathematics
#include <glm/glm.hpp>
#include <QGLFormat> //Error here
#include <QGLWidget> //and here
#include <QMouseEvent>
#include <QKeyEvent>
...
with a main quite simple
#include <qapplication.h>
#include <QString>
#include "viewer.h"
int main(int argc,char** argv) {
QApplication application(argc,argv);
Viewer viewer;
viewer.show();
return application.exec();
}

Getting file not found error using clang LibASTMatchers

I am experiencing an issue with CLang's libastmatchers while working with Postgres sources: it can't find include file. This error is reproduced only when CLangTool is created from two files. If it is created for a separate file, there is no error and function is successfully matched.
Full error:
/home/myuser/postgres/src/conditional.c:1:10: fatal error: 'pg_config_ext.h' file not found
#include "pg_config_ext.h"
^~~~~~~~~~~~~~~~~
1 error generated.
Error while processing /home/myuser/postgres/src/conditional.c.
Directory structure:
postgres/
|-- compile_commands.json
|-- pg_config_ext.h
`-- src
|-- backend
| `-- nodeHash.c
`-- conditional.c
File contents:
nodeHash.c is empty;
conditional.c:
#include "pg_config_ext.h"
pg_config_ext.h:
int f();
compile_commands.json:
[ {
"arguments": [
"clang",
"-c",
"-I..",
"/home/myuser/postgres/src/conditional.c"
],
"directory": "/home/myuser/postgres/src",
"file": "/home/myuser/postgres/src/conditional.c"
},
{
"arguments": [
"clang",
"-c",
"-I../..",
"/home/myuser/postgres/src/backend/nodeHash.c"
],
"directory": "/home/myuser/postgres/src/backend",
"file": "/home/myuser/postgres/src/backend/nodeHash.c"
}
]
CMakeLists.txt:
cmake_minimum_required(VERSION 3.16)
project(untitled)
set(CMAKE_CXX_STANDARD 17)
find_package(Clang REQUIRED)
include_directories(${CLANG_INCLUDE_DIRS})
add_definitions(${CLANG_DEFINITIONS})
add_executable(clang_error main.cpp)
target_link_libraries(clang_error PUBLIC clangTooling clangBasic clangASTMatchers)
main.cpp:
#include <clang/ASTMatchers/ASTMatchFinder.h>
#include <clang/Frontend/FrontendActions.h>
#include <clang/Tooling/CommonOptionsParser.h>
#include <clang/Frontend/CompilerInstance.h>
#include <clang/Tooling/Tooling.h>
#include <string>
#include <vector>
#include <memory>
#include <iostream>
using namespace clang::ast_matchers;
using namespace clang;
using namespace clang::tooling;
using namespace std;
string prefix = "/home/myuser/";
string ccPath = prefix + "postgres/";
vector<string> files = {
prefix + "postgres/src/backend/nodeHash.c", // if you comment out this line, there will be no error
prefix + "postgres/src/conditional.c"
};
class Fetcher : public MatchFinder::MatchCallback {
public:
void run(const MatchFinder::MatchResult &Result) override {
if (const auto *FS = Result.Nodes.getNodeAs<FunctionDecl>("function")) {
std::cout << "Matched"; // Matches only if one file, not two
}
}
};
int main() {
unique_ptr<clang::tooling::ClangTool> clangTool;
unique_ptr<Fetcher> fetcherInstance;
MatchFinder finder;
static const DeclarationMatcher functionMatcher = functionDecl().bind("function");
string errMsg;
shared_ptr<clang::tooling::CompilationDatabase> cDb = clang::tooling::CompilationDatabase::autoDetectFromDirectory(ccPath, errMsg);
std::cout << errMsg; // No output
clangTool = std::make_unique<ClangTool>(*cDb, files);
fetcherInstance = std::make_unique<Fetcher>();
finder.addMatcher(functionMatcher, fetcherInstance.get());
clangTool->run(newFrontendActionFactory(&finder).get());
}
I am using CLang version 10.0.0
Perhaps, this is the same issue, but there is no answer.

Cannot open include file: 'cxxabi.h': No such file or directory

I am making a game that can be played on mac and windows with cocos2d-x.
I first wrote the code in mac's Xcode, and it worked on mac.
When I took the project to windows and tried to build it in Visual Studio 2017, an error occurred.
Error C1083 Cannot open include file: 'cxxabi.h': No such file or directory Narazumono c:\users\masanori\desktop\narazumono3.17\classes_win\nrzcoding.cpp 10
I use cxxabi.h to get the class name of the object.
#include "NRZCoding.h"
#include <cxxabi.h>
#include <cstdio>
#include <algorithm>
#include "NRZUtils.h"
using namespace std;
USING_NS_CC;
namespace NRZCoding {
...
const string& EncodableObject::getClassName()
{
if (_className.size() > 0) {
return _className;
}
const type_info& id = typeid(*this);
int stat;
char *name = abi::__cxa_demangle(id.name(),0,0,&stat);
CCASSERT(name != NULL && stat == 0, "failed to demangle");
_className = string(name);
free(name);
return _className;
}
...
What do I need to do?
I am using cocos2d-x 3.17.1 and Visual Studio 2017.
Thank you.

Qt linker errors windows

I'm trying to run this code, but all I get is linker errors and don't really know what to do or what I'm doing wrong here. Been struggling way too long with this now, any help is greatly appreciated so I can get this thing going. This is also my first Qt-application ever.
Running Qt Creator 3.5.1, Based on Qt 5.5.1 (MSVC 2013, 32 bit)
Compiler: Microsoft Visual C++ Compiler 12.0
OS: Windows 8.1 Pro 64-bit
I have Qt project where I have files:
Hasher.h
#ifndef HASHER_H
#define HASHER_H
#include <QString>
#include <QCryptographicHash>
class Hasher : public QCryptographicHash
{
public:
Hasher(const QByteArray &data, Algorithm method); /* Constructor */
~Hasher(); /* Destructor */
QString name, output;
private:
QCryptographicHash *QCryptObject;
};
#endif // HASHER_H
Hasher.cpp
#include "hasher.h"
/* Destructor */
Hasher::~Hasher() {
}
/*
* Constructor Hasher(QByteArray &, Algorithm) generates hash
* from given input with given algorithm-method
*/
Hasher::Hasher(const QByteArray &data, Algorithm method) {
QByteArray result = this->QCryptObject->hash(data, method);
this->output = result.toHex();
}
main.cpp
#include <QCoreApplication>
#include <QString>
#include <QFile>
#include <QDebug>
#include "hasher.h"
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
QString fileName;
QTextStream stream(stdin);
qDebug() << "MD5 generator!" << endl;
qDebug() << "Give filename to generate checksum from: ";
fileName = stream.readLine();
QFile* file = new QFile(fileName);
if(file->open(QIODevice::ReadOnly))
{
Hasher hasher(file->readAll(), QCryptographicHash::Md5);
qDebug() << "MD5 Hash of " << fileName << " is: " << hasher.output << endl;
file->close();
}
return a.exec();
}
Errors I get:
main.obj:-1: error: LNK2019: unresolved external symbol "public: __cdecl Hasher::Hasher(class QByteArray const &,enum QCryptographicHash::Algorithm)" (??0Hasher##QEAA#AEBVQByteArray##W4Algorithm#QCryptographicHash###Z) referenced in function main
main.obj:-1: error: LNK2019: unresolved external symbol "public: __cdecl Hasher::~Hasher(void)" (??1Hasher##QEAA#XZ) referenced in function main
debug\MD5-generator.exe:-1: error: LNK1120: 2 unresolved externals
.pro file
QT += core
QT -= gui
TARGET = MD5-generator
CONFIG += console
CONFIG -= app_bundle
TEMPLATE = app
SOURCES += main.cpp \
hasher.cpp
HEADERS += \
hasher.h
So, the linker error resulted from not updated makefiles and object files, since the new Hasher.cpp was not compled at all. In that case rebuilding project may help: Clean, Run qmake, Build.
In Hasher::Hasher you need to call base class constructor:
Hasher::Hasher(const QByteArray &data, Algorithm method)
: QCryptographicHash(method)
{
QByteArray result = this->hash(data, method);
this->output = result.toHex();
}
I have no idea why MSVC compiles that code at all, it should not even get to linking.