Privacy policyContactsAbout siteOpinionsGitHubDonate
© EVILEG 2015-2018
Recommend hosting
TIMEWEB
Dec. 12, 2018, 8:57 p.m.

C++

Boost, static, static link

I propose to write a small application that will have two subdirectories. One of which will compile the executable file, and the second will contain a statically linked library.

As a result, the project will look like this.

Nov. 29, 2018, 7:10 p.m.

Boost

cpp, Boost, linking, C++, static

A small note about static linking Boost, so as not to forget.

Initial data:

  • OS Windows
  • MSVC 2017 64bit
  • Boost 1.68.0
  • CMake project
An example will be shown in the simplest version without special variable settings. Maximum default.

C
Sept. 11, 2018, 9:14 a.m.
Cobra91151

Здравствуйте! При статической компиляции Qt с MySQL выбрасывает:



+ cd /d D:\QtBuild\Src\config.tests\mysql && D:\QtBuild\Src\qtbase\bin\qmake.exe "CONFIG -= qt debug_and_release app_bundle lib_bundle" "CONFIG += static warn_off console single_arch" "QMAKE_LIBDIR += C:\\MySQL\\mysql-5.7.23-win32\\lib C:\\OpenSSL\\openssl-1.0.2l-vs2017\\lib" "INCLUDEPATH += C:\\MySQL\\mysql-5.7.23-win32\\include C:\\OpenSSL\\openssl-1.0.2l-vs2017\\include" "LIBS += -lmysqlclient" D:/QtBuild/Src/config.tests/mysql
+ cd /d D:\QtBuild\Src\config.tests\mysql && set MAKEFLAGS=& nmake
> Microsoft (R) Program Maintenance Utility Version 14.15.26726.0
> Copyright (C) Microsoft Corporation.  All rights reserved.
> 	cl -c -nologo -Zc:wchar_t -FS -Zc:rvalueCast -Zc:inline -Zc:strictStrings -Zc:throwingNew -Zc:referenceBinding -Zi -MDd -W0 -EHsc /Fdmysql.vc.pdb -DUNICODE -D_UNICODE -DWIN32 -I. -IC:\MySQL\mysql-5.7.23-win32\include -IC:\OpenSSL\openssl-1.0.2l-vs2017\include -ID:\QtBuild\Src\qtbase\mkspecs\win32-msvc -Fo @C:\Users\cobra\AppData\Local\Temp\nmC064.tmp
> main.cpp
> 	link /NOLOGO /DYNAMICBASE /NXCOMPAT /DEBUG /SUBSYSTEM:CONSOLE "/MANIFESTDEPENDENCY:type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' publicKeyToken='6595b64144ccf1df' language='*' processorArchitecture='*'" /MANIFEST:embed /OUT:mysql.exe @C:\Users\cobra\AppData\Local\Temp\nmC2B7.tmp
> LINK : warning LNK4098: defaultlib 'MSVCRT' conflicts with use of other libs; use /NODEFAULTLIB:library
> mysqlclient.lib(xml.obj) : error LNK2001: unresolved external symbol __imp__sprintf
> mysqlclient.lib(libmysql.obj) : error LNK2001: unresolved external symbol __imp__sprintf
> mysqlclient.lib(my_time.obj) : error LNK2001: unresolved external symbol __imp__sprintf
> mysqlclient.lib(client.obj) : error LNK2001: unresolved external symbol __imp__sprintf
> mysqlclient.lib(ctype.obj) : error LNK2001: unresolved external symbol __imp__sprintf
> mysqlclient.lib(my_init.obj) : error LNK2019: unresolved external symbol __imp__RegCloseKey@4 referenced in function _win32_have_tcpip
> mysqlclient.lib(my_init.obj) : error LNK2019: unresolved external symbol __imp__RegEnumValueA@32 referenced in function _win_init_registry
> mysqlclient.lib(my_init.obj) : error LNK2019: unresolved external symbol __imp__RegOpenKeyExA@20 referenced in function _win32_have_tcpip
> mysqlclient.lib(my_default.obj) : error LNK2001: unresolved external symbol __imp____iob_func
> mysqlclient.lib(log_client.obj) : error LNK2001: unresolved external symbol __imp____iob_func
> mysqlclient.lib(my_init.obj) : error LNK2001: unresolved external symbol __imp____iob_func
> mysqlclient.lib(my_winfile.obj) : error LNK2001: unresolved external symbol __imp____iob_func
> mysqlclient.lib(my_mess.obj) : error LNK2001: unresolved external symbol __imp____iob_func
> mysqlclient.lib(typelib.obj) : error LNK2001: unresolved external symbol __imp____iob_func
> mysqlclient.lib(my_mess.obj) : error LNK2019: unresolved external symbol __imp__fprintf referenced in function _my_message_stderr
> mysqlclient.lib(typelib.obj) : error LNK2001: unresolved external symbol __imp__fprintf
> mysqlclient.lib(log_client.obj) : error LNK2001: unresolved external symbol __imp__fprintf
> mysqlclient.lib(client_authentication.obj) : error LNK2019: unresolved external symbol "__declspec(dllimport) char const * __cdecl std::_Winerror_map(int)" (__imp_?_Winerror_map@std@@YAPBDH@Z) referenced in function "public: virtual class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __thiscall std::_System_error_category::message(int)const " (?message@_System_error_category@std@@UBE?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@2@H@Z)
> mysqlclient.lib(sha2_password_common.obj) : error LNK2001: unresolved external symbol "__declspec(dllimport) char const * __cdecl std::_Winerror_map(int)" (__imp_?_Winerror_map@std@@YAPBDH@Z)
> mysqlclient.lib(my_default.obj) : error LNK2019: unresolved external symbol __imp__printf referenced in function _my_load_defaults
> mysqlclient.lib(ssl.obj) : error LNK2019: unresolved external symbol __imp___snprintf referenced in function _ya_SSL_ASN1_TIME_to_string
> mysqlclient.lib(log_client.obj) : error LNK2019: unresolved external symbol __imp__vfprintf referenced in function "void __cdecl error_log_vprint(enum error_log_level::type,char const *,char *)" (?error_log_vprint@@YAXW4type@error_log_level@@PBDPAD@Z)
> mysqlclient.lib(common.obj) : error LNK2019: unresolved external symbol __imp__EqualSid@8 referenced in function "public: bool __thiscall Sid::operator==(class Sid const &)" (??8Sid@@QAE_NABV0@@Z)
> mysqlclient.lib(common.obj) : error LNK2019: unresolved external symbol __imp__GetTokenInformation@20 referenced in function "public: __thiscall Sid::Sid(void *)" (??0Sid@@QAE@PAX@Z)
> mysqlclient.lib(common.obj) : error LNK2019: unresolved external symbol __imp__IsValidSid@4 referenced in function "public: bool __thiscall Sid::is_valid(void)const " (?is_valid@Sid@@QBE_NXZ)
> mysqlclient.lib(common.obj) : error LNK2019: unresolved external symbol __imp__LookupAccountNameW@28 referenced in function "public: __thiscall Sid::Sid(wchar_t const *)" (??0Sid@@QAE@PB_W@Z)
> mysqlclient.lib(random.obj) : error LNK2019: unresolved external symbol __imp__CryptAcquireContextA@20 referenced in function "public: __thiscall TaoCrypt::OS_Seed::OS_Seed(void)" (??0OS_Seed@TaoCrypt@@QAE@XZ)
> mysqlclient.lib(random.obj) : error LNK2019: unresolved external symbol __imp__CryptReleaseContext@8 referenced in function "public: __thiscall TaoCrypt::OS_Seed::~OS_Seed(void)" (??1OS_Seed@TaoCrypt@@QAE@XZ)
> mysqlclient.lib(random.obj) : error LNK2019: unresolved external symbol __imp__CryptGenRandom@12 referenced in function "public: void __thiscall TaoCrypt::OS_Seed::GenerateSeed(unsigned char *,unsigned int)" (?GenerateSeed@OS_Seed@TaoCrypt@@QAEXPAEI@Z)
> mysql.exe : fatal error LNK1120: 17 unresolved externals
> NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.15.26726\bin\HostX86\x86\link.EXE"' : return code '0x460'
> Stop.
 => source failed verification.
Trying source 6 (type inline) of library mysql ...
+ cd /d D:\QtBuild\Src\config.tests\mysql && D:\QtBuild\Src\qtbase\bin\qmake.exe "CONFIG -= qt debug_and_release app_bundle lib_bundle" "CONFIG += static warn_off console single_arch" "QMAKE_LIBDIR += C:\\MySQL\\mysql-5.7.23-win32\\lib C:\\OpenSSL\\openssl-1.0.2l-vs2017\\lib" "INCLUDEPATH += C:\\MySQL\\mysql-5.7.23-win32\\include C:\\OpenSSL\\openssl-1.0.2l-vs2017\\include" "LIBS += -lmysqlclient" D:/QtBuild/Src/config.tests/mysql
+ cd /d D:\QtBuild\Src\config.tests\mysql && set MAKEFLAGS=& nmake clean && set MAKEFLAGS=& nmake
> Microsoft (R) Program Maintenance Utility Version 14.15.26726.0
> Copyright (C) Microsoft Corporation.  All rights reserved.
> 	del main.obj
> 	del mysql.vc.pdb mysql.ilk mysql.idb
> Microsoft (R) Program Maintenance Utility Version 14.15.26726.0
> Copyright (C) Microsoft Corporation.  All rights reserved.
> 	cl -c -nologo -Zc:wchar_t -FS -Zc:rvalueCast -Zc:inline -Zc:strictStrings -Zc:throwingNew -Zc:referenceBinding -Zi -MDd -W0 -EHsc /Fdmysql.vc.pdb -DUNICODE -D_UNICODE -DWIN32 -I. -IC:\MySQL\mysql-5.7.23-win32\include -IC:\OpenSSL\openssl-1.0.2l-vs2017\include -ID:\QtBuild\Src\qtbase\mkspecs\win32-msvc -Fo @C:\Users\cobra\AppData\Local\Temp\nmC3CF.tmp
> main.cpp
> 	link /NOLOGO /DYNAMICBASE /NXCOMPAT /DEBUG /SUBSYSTEM:CONSOLE "/MANIFESTDEPENDENCY:type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' publicKeyToken='6595b64144ccf1df' language='*' processorArchitecture='*'" /MANIFEST:embed /OUT:mysql.exe @C:\Users\cobra\AppData\Local\Temp\nmC632.tmp
> LINK : warning LNK4098: defaultlib 'MSVCRT' conflicts with use of other libs; use /NODEFAULTLIB:library
> mysqlclient.lib(xml.obj) : error LNK2001: unresolved external symbol __imp__sprintf
> mysqlclient.lib(libmysql.obj) : error LNK2001: unresolved external symbol __imp__sprintf
> mysqlclient.lib(my_time.obj) : error LNK2001: unresolved external symbol __imp__sprintf
> mysqlclient.lib(client.obj) : error LNK2001: unresolved external symbol __imp__sprintf
> mysqlclient.lib(ctype.obj) : error LNK2001: unresolved external symbol __imp__sprintf
> mysqlclient.lib(my_init.obj) : error LNK2019: unresolved external symbol __imp__RegCloseKey@4 referenced in function _win32_have_tcpip
> mysqlclient.lib(my_init.obj) : error LNK2019: unresolved external symbol __imp__RegEnumValueA@32 referenced in function _win_init_registry
> mysqlclient.lib(my_init.obj) : error LNK2019: unresolved external symbol __imp__RegOpenKeyExA@20 referenced in function _win32_have_tcpip
> mysqlclient.lib(my_default.obj) : error LNK2001: unresolved external symbol __imp____iob_func
> mysqlclient.lib(log_client.obj) : error LNK2001: unresolved external symbol __imp____iob_func
> mysqlclient.lib(my_init.obj) : error LNK2001: unresolved external symbol __imp____iob_func
> mysqlclient.lib(my_winfile.obj) : error LNK2001: unresolved external symbol __imp____iob_func
> mysqlclient.lib(my_mess.obj) : error LNK2001: unresolved external symbol __imp____iob_func
> mysqlclient.lib(typelib.obj) : error LNK2001: unresolved external symbol __imp____iob_func
> mysqlclient.lib(my_mess.obj) : error LNK2019: unresolved external symbol __imp__fprintf referenced in function _my_message_stderr
> mysqlclient.lib(typelib.obj) : error LNK2001: unresolved external symbol __imp__fprintf
> mysqlclient.lib(log_client.obj) : error LNK2001: unresolved external symbol __imp__fprintf
> mysqlclient.lib(client_authentication.obj) : error LNK2019: unresolved external symbol "__declspec(dllimport) char const * __cdecl std::_Winerror_map(int)" (__imp_?_Winerror_map@std@@YAPBDH@Z) referenced in function "public: virtual class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __thiscall std::_System_error_category::message(int)const " (?message@_System_error_category@std@@UBE?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@2@H@Z)
> mysqlclient.lib(sha2_password_common.obj) : error LNK2001: unresolved external symbol "__declspec(dllimport) char const * __cdecl std::_Winerror_map(int)" (__imp_?_Winerror_map@std@@YAPBDH@Z)
> mysqlclient.lib(my_default.obj) : error LNK2019: unresolved external symbol __imp__printf referenced in function _my_load_defaults
> mysqlclient.lib(ssl.obj) : error LNK2019: unresolved external symbol __imp___snprintf referenced in function _ya_SSL_ASN1_TIME_to_string
> mysqlclient.lib(log_client.obj) : error LNK2019: unresolved external symbol __imp__vfprintf referenced in function "void __cdecl error_log_vprint(enum error_log_level::type,char const *,char *)" (?error_log_vprint@@YAXW4type@error_log_level@@PBDPAD@Z)
> mysqlclient.lib(common.obj) : error LNK2019: unresolved external symbol __imp__EqualSid@8 referenced in function "public: bool __thiscall Sid::operator==(class Sid const &)" (??8Sid@@QAE_NABV0@@Z)
> mysqlclient.lib(common.obj) : error LNK2019: unresolved external symbol __imp__GetTokenInformation@20 referenced in function "public: __thiscall Sid::Sid(void *)" (??0Sid@@QAE@PAX@Z)
> mysqlclient.lib(common.obj) : error LNK2019: unresolved external symbol __imp__IsValidSid@4 referenced in function "public: bool __thiscall Sid::is_valid(void)const " (?is_valid@Sid@@QBE_NXZ)
> mysqlclient.lib(common.obj) : error LNK2019: unresolved external symbol __imp__LookupAccountNameW@28 referenced in function "public: __thiscall Sid::Sid(wchar_t const *)" (??0Sid@@QAE@PB_W@Z)
> mysqlclient.lib(random.obj) : error LNK2019: unresolved external symbol __imp__CryptAcquireContextA@20 referenced in function "public: __thiscall TaoCrypt::OS_Seed::OS_Seed(void)" (??0OS_Seed@TaoCrypt@@QAE@XZ)
> mysqlclient.lib(random.obj) : error LNK2019: unresolved external symbol __imp__CryptReleaseContext@8 referenced in function "public: __thiscall TaoCrypt::OS_Seed::~OS_Seed(void)" (??1OS_Seed@TaoCrypt@@QAE@XZ)
> mysqlclient.lib(random.obj) : error LNK2019: unresolved external symbol __imp__CryptGenRandom@12 referenced in function "public: void __thiscall TaoCrypt::OS_Seed::GenerateSeed(unsigned char *,unsigned int)" (?GenerateSeed@OS_Seed@TaoCrypt@@QAEXPAEI@Z)
> mysql.exe : fatal error LNK1120: 17 unresolved externals
> NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.15.26726\bin\HostX86\x86\link.EXE"' : return code '0x460'
> Stop.
 => source failed verification.
test config.sqldrivers.libraries.mysql FAILED
looking for library oci
Trying source 0 (type inline) of library oci ...
+ cd /d D:\QtBuild\Src\config.tests\oci && D:\QtBuild\Src\qtbase\bin\qmake.exe "CONFIG -= qt debug_and_release app_bundle lib_bundle" "CONFIG += static warn_off console single_arch" "QMAKE_LIBDIR += C:\\MySQL\\mysql-5.7.23-win32\\lib C:\\OpenSSL\\openssl-1.0.2l-vs2017\\lib" "INCLUDEPATH += C:\\MySQL\\mysql-5.7.23-win32\\include C:\\OpenSSL\\openssl-1.0.2l-vs2017\\include" "LIBS += -loci" D:/QtBuild/Src/config.tests/oci
+ cd /d D:\QtBuild\Src\config.tests\oci && set MAKEFLAGS=& nmake
> Microsoft (R) Program Maintenance Utility Version 14.15.26726.0
> Copyright (C) Microsoft Corporation.  All rights reserved.
> 	cl -c -nologo -Zc:wchar_t -FS -Zc:rvalueCast -Zc:inline -Zc:strictStrings -Zc:throwingNew -Zc:referenceBinding -Zi -MDd -W0 -EHsc /Fdoci.vc.pdb -DUNICODE -D_UNICODE -DWIN32 -I. -IC:\MySQL\mysql-5.7.23-win32\include -IC:\OpenSSL\openssl-1.0.2l-vs2017\include -ID:\QtBuild\Src\qtbase\mkspecs\win32-msvc -Fo @C:\Users\cobra\AppData\Local\Temp\nmC6EC.tmp
> main.cpp
> .\main.cpp(2): fatal error C1083: Cannot open include file: 'oci.h': No such file or directory
> NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.15.26726\bin\HostX86\x86\cl.EXE"' : return code '0x2'
> Stop.

Использую Qt 5.9.6, MySQL 5.7.23, Visual Studio 2017. Компилирую под x86 архитектуру. Все работает если использовать динамическую библиотеку libmysql.lib, но если использовать статическу библиотеку mysqlclient.lib выбрасывает ошибки.



Я создал batch файл для конфигурации Qt:


SET /P qtBuildType=Qt build type (shared/static): 
SET /P qtBuildMySqlIncludePath=MySql include path: 
SET /P qtBuildMySqlLibPath=MySql lib path: 
SET /P qtBuildOpenSSLIncludePath=OpenSSL include path: 
SET /P qtBuildOpenSSLLibPath=OpenSSL lib path: 
SET /P qtBuildPath=Enter Qt build path: 
configure.bat -debug-and-release -%qtBuildType% -opensource -nomake tools -nomake examples -no-ltcg -sql-mysql -I "%qtBuildMySqlIncludePath%" -L "%qtBuildMySqlLibPath%" MYSQL_LIBS="-lmysqlclient" -ssl -openssl -openssl-linked -I "%qtBuildOpenSSLIncludePath%" -L "%qtBuildOpenSSLLibPath%" OPENSSL_LIBS="-lUser32 -lAdvapi32 -lGdi32 -lCrypt32" OPENSSL_LIBS_DEBUG="-lssleay32MTd -llibeay32MTd" OPENSSL_LIBS_RELEASE="-lssleay32MT -llibeay32MT" -prefix "%qtBuildPath%"

Я хочу чтобы эта бибилиотека была вшита в .exe файл. Также я пробовал создавать с ней статический MFC проект для теста в VS 2017. Выбрасывает такие-же ошибки (добавил скриншот). Как думаете в чем может быть проблема? Спасибо.

f
Aug. 22, 2018, 8:10 a.m.
fryn3

Установил статический QT по видео . Установил QWT по видео .
В файле C:\qwt-6.1.3\qwtconfig.pri закоменчена строка:

######################################################################
# Build the static/shared libraries.
# If QwtDll is enabled, a shared library is built, otherwise
# it will be a static library.
######################################################################

#QWT_CONFIG           += QwtDll

Создаю маленький проект(код ниже). Динамически все собирается и запускается. Статически собирается, но вылетает ошибка:

QWidget: Must construct a QApplication before a QWidget

Ошибка при запуске статического приложения


Путь к статик Qt: C:\Qt\Static5111\5.11.1_Static Путь к Qwt: C:\qwt-6.1.3 Проект: qwtTemp.pro

QT       += core gui widgets

TARGET = qwtTemp
TEMPLATE = app

DEFINES += QT_DEPRECATED_WARNINGS


CONFIG += c++11

SOURCES += \
        main.cpp \
        widget.cpp

HEADERS += \
        widget.h


# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target

CONFIG += qwt

widget.h

#ifndef WIDGET_H
#define WIDGET_H

#include <QWidget>
#include <qwt_plot.h>

class Widget : public QWidget
{
    Q_OBJECT

public:
    Widget(QWidget *parent = 0);
    ~Widget();

    QwtPlot *p;
};

#endif // WIDGET_H

widget.cpp

#include "widget.h"

Widget::Widget(QWidget *parent)
    : QWidget(parent)
{
    p = new QwtPlot();
}

Widget::~Widget()
{
    delete p;
}

main.cpp

#include "widget.h"
#include <QApplication>

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    Widget w;
    w.show();
    w.p->show();
    return a.exec();
}
July 5, 2017, 10:05 a.m.

QML

qml, singleton, static

The notion of static methods that are used in QML differs somewhat from the classical one in C ++, when static methods are created in the class that can be used referring to the class name, rather than to a specific object. In the case of QML, things are somewhat different. In order to use such methods in QML, which are present in the C ++ class, it is necessary to register a Singleton object that will provide the required methods, and these methods should no longer be static in themselves. They should at least be labeled with the Q_INVOKABLE macro so that they can be used in QML.

To register Singleton , you need to use the qmlRegisterSingletonType function, which in addition to the standard parameters that are passed to qmlRegisterType, you must also pass the static singletonProvider function, which you also write yourself.

Last comments
V
Feb. 14, 2019, 6:41 p.m.
Vlad15007

Спасибо огромное! Заработало!
А
Feb. 12, 2019, 9:26 a.m.
Александр90

Сам разборался, спасибо.
А
Feb. 12, 2019, 8:19 a.m.
Александр90

День добрый! Можешь выложить форму mainwindow.ui от урока? Заранее спасибо
Feb. 11, 2019, 10:51 a.m.
Евгений Легоцкой

Нет, у меня проблема с жёстким диском случилась, занимался восстановлением ПК, ещё пару вечеров придётся этим заниматься, увы.
Now discuss on the forum
Feb. 15, 2019, 9:22 p.m.
IscanderChe

Доброй ночи.Скромно напоминаю о своём вопросе...
Feb. 15, 2019, 3:36 p.m.
Евгений Легоцкой

Ну я тут нашёл одно решение, но сам его не проверял. Вам нужно помещать фамилии скорее всего в ячейки заголовка, и потом просто перерисовывать их QHeaderView * header = m_ui->tableWidget...
Feb. 15, 2019, 7:53 a.m.
Евгений Легоцкой

Добрый день! Не работал с remoteobjects, поэтому глянул документацию, чтобы рассмотреть, что это за зверь. После просмотра документации сложилось стойкой впечатление, что это вполне возм...
m
Feb. 14, 2019, 6:28 p.m.
mr_roman

Нашел решение на Java. Удалось интегрировать в проект сервиса на Qt, теперь из Qt запускаю Java-код акселерометра.
Feb. 14, 2019, 11 a.m.
Евгений Легоцкой

ok. I see. You changed related name Try this {% if goal.joined.all|user_in:request.user %}
Join us in social networks

For registered users on the site there is a minimum amount of advertising