Using a Static Library I Created
-
Hi,
Your LIBS entry is wrong. You need to pass the -L option with the path to where your library is located so the linker can find it. You are also missing the -l before your library name.
Also, please use forward slashes in your paths even on Windows.
-
Hi,
Your LIBS entry is wrong. You need to pass the -L option with the path to where your library is located so the linker can find it. You are also missing the -l before your library name.
Also, please use forward slashes in your paths even on Windows.
-
Again: stop using backslashes for your paths.
-L is to give a folder
-l (which lower case L) is used to pass the library name. -
Again: stop using backslashes for your paths.
-L is to give a folder
-l (which lower case L) is used to pass the library name.@SGaist No more \ in paths. I tried:
INCLUDEPATH += \d:/MyLibraries/ LIBS = += -L\MyLibraries/libMy3DLib -llibMy3DLib
What I assume is the following:
The first statement is the actual address of the folder that contains the library I created. The leading \ I am assuming is a concatenation symbol.
As for the second statement, -L says there is a folder name MyLibraries and the -l says that the library is libMy3DLib which is a file with extension of .a.Finally I assume that```
#include "vector4.h"
#include "matrix4x4.h"
#include "freefun.h" -
@SGaist No more \ in paths. I tried:
INCLUDEPATH += \d:/MyLibraries/ LIBS = += -L\MyLibraries/libMy3DLib -llibMy3DLib
What I assume is the following:
The first statement is the actual address of the folder that contains the library I created. The leading \ I am assuming is a concatenation symbol.
As for the second statement, -L says there is a folder name MyLibraries and the -l says that the library is libMy3DLib which is a file with extension of .a.Finally I assume that```
#include "vector4.h"
#include "matrix4x4.h"
#include "freefun.h"@ofmrew I Found some Qt documentation that should fix the problem but it does not, namely:
Variables
The fundamental behavior of qmake is influenced by variable declarations that define the build process of each project. Some of these declare resources, such as headers and source files, that are common to each platform. Others are used to customize the behavior of compilers and linkers on specific platforms.Platform-specific variables follow the naming pattern of the variables which they extend or modify, but include the name of the relevant platform in their name. For example, a makespec may use QMAKE_LIBS to specify a list of libraries that each project needs to link against, and QMAKE_LIBS_X11 would be used to extend this list.
ANDROID_ABIS
Note: This variable applies only to Android targets.Specifies a list of Android target ABIs. Valid values are: armeabi-v7a, arm64-v8a, x86, x86_64.
You can provide the ABIs as a qmake argument:
qmake ANDROID_ABIS="armeabi-v7a arm64-v8a"
Note: It is possible to use this variable inside the *.pro file, however, it is not recommended since it will override any ABIs specified on the qmake command line.ANDROID_API_VERSION
Note: This variable applies only to Android targets.Specifies the Android API level number. For more information, see Android Build Numbers.
ANDROID_APPLICATION_ARGUMENTS
Note: This variable applies only to Android targets.Specifies extra command-line arguments to the Android app using the AndroidManifest.xml with the tag "android.app.arguments". This takes a string of arguments:
ANDROID_APPLICATION_ARGUMENTS = "arg1 arg2 arg3"
ANDROID_BUNDLED_JAR_DEPENDENCIES
Note: This variable applies only to Android modules.This is useful when writing a Qt module. It specifies a list of pre-bundled dependencies used by the module in a .jar format, for example:
ANDROID_BUNDLED_JAR_DEPENDENCIES += jar/Qt6Android.jar
ANDROID_DEPLOYMENT_DEPENDENCIES
Note: This variable applies only to Android targets.By default, androiddeployqt will detect the dependencies of your application. However, since run-time usage of plugins cannot be detected, there could be false positives, as your application might depend on any plugin that is a potential dependency. If you want to minimize the size of your APK, it's possible to override the automatic detection using the this variable. This should contain a list of all Qt files which need to be included, with paths relative to the Qt install root.
Note: Only the Qt files specified with this variable are included. Failing to include all the correct files can result in crashes. It's also important to make sure the files are listed in the correct loading order. This variable provides a way to override the automatic detection entirely, so if a library is listed before its dependencies, it will fail to load on some devices.
ANDROID_DEPLOYMENT_SETTINGS_FILE
Note: This variable applies only to Android targets.Specifies the path to the android-deployment-settings.json file needed by androiddeployqt and androidtestrunner. This overrides the path to the settings file generated by qmake, thus you have to make sure to provide a valid settings file.
ANDROID_EXTRA_LIBS
Note: This variable applies only to Android targets.A list of external libraries that will be copied into your application's libs folder and loaded on start-up. This can be used, for instance, to enable OpenSSL in your application. For more information, see Adding OpenSSL Support for Android.
To include external libraries for multiple ABIs, where each ABIs has its own directory, use the following:
for (abi, ANDROID_ABIS): ANDROID_EXTRA_LIBS += $$PWD/$${abi}/library_name.so
Otherwise, if the ABI is included in the library name, use the following:for (abi, ANDROID_ABIS): ANDROID_EXTRA_LIBS += $$PWD/library_name_$${abi}.so
ANDROID_EXTRA_PLUGINS
Note: This variable applies only to Android targets.Specifies a path to C++ plugins or resources that your application has to bundle but that cannot be delivered through the assets system, such as QML plugins. With this variable, androiddeployqt will make sure everything is packaged and deployed properly.
ANDROID_EXTRA_PLUGINS must point to the directory where the extra plugin(s) are built. In addition, the build directory structure must follow a naming convention similar to Qt plugins, that is, plugins/<plugin name>.
The plugins libraries should have the name format libplugins_<type><name><abi>.so. To achieve that the plugin pro file could be defined as follows:
TEMPLATE = lib
CONFIG += pluginPLUGIN_TYPE = imageformats
DESTDIR = $$top_builddir/plugins/myplugin
TARGET = $$qt5LibraryTarget(myplugin, "plugins/$$PLUGIN_TYPE/")
with top_builddir defined in .qmake.conf as:top_builddir=$$shadowed($$PWD)
This will ensure that the correct name mangling is applied to the plugin library (plugins/myplugin/libplugins_imageformats_myplugin_armeabi-v7a.so).Then, assuming an extra image format plugin myplugin is built as $$DESTDIR/plugins/myplugin/, the following ensures it is packaged correctly:
ANDROID_EXTRA_PLUGINS += $$top_builddir/plugins
ANDROID_FEATURES
Note: This variable applies only to Android modules.Specifies a module's features list:
ANDROID_FEATURES += android.hardware.location.gps
For more information, see Android <uses-feature> Docs.ANDROID_LIB_DEPENDENCIES
Note: This variable applies only to Android modules.This is useful when writing a Qt module. It specifies a list of pre-built dependencies used by the module, for example:
ANDROID_LIB_DEPENDENCIES +=
plugins/libplugins_platforms_qtforandroid.so
ANDROID_MIN_SDK_VERSION
Note: This variable applies only to Android targets.Specifies the minimum Android API level for the project. By default, this variable is set to API level 23.
ANDROID_PACKAGE_SOURCE_DIR
Note: This variable applies only to Android targets.Specifies the path for a custom Android package template. The Android package template contains:
AndroidManifest.xml file
build.gradle file and other Gradle scripts
res/values/libs.xml file
The path specified by this variable can contain custom Java classes under src directory. By default, the androiddeployqt tool copies the application template from the Qt for Android installation path into your project's build directory, then it copies the contents of the path specified by this variable on top of that, overwriting any existing files. For instance, you can make a custom AndroidManifest.xml for your application, then place this directly into the directory specified by this variable.ANDROID_PERMISSIONS
Note: This variable applies only to Android modules.Specifies a module's permissions list:
ANDROID_PERMISSIONS += android.permission.ACCESS_FINE_LOCATION
For more information, see Android <uses-permission> Docs.ANDROID_TARGET_SDK_VERSION
Note: This variable applies only to Android targets.Specifies the target Android API level for the project. By default, this variable is set to API level 30.
ANDROID_VERSION_CODE
Note: This variable applies only to Android targets.Specifies the application's version number. For more information, see Android App Versioning.
ANDROID_VERSION_NAME
Note: This variable applies only to Android targets.Specifies the application's version in as a human readable string. For more information, see Android App Versioning.
CONFIG
Specifies project configuration and compiler options. The values are recognized internally by qmake and have special meaning.Note: The values are case-sensitive.
The following CONFIG values control compiler and linker flags:
Option Description
release The project is to be built in release mode. If debug is also specified, the last one takes effect.
debug The project is to be built in debug mode.
debug_and_release The project is prepared to be built in both debug and release modes.
debug_and_release_target This option is set by default. If debug_and_release is also set, the debug and release builds end up in separate debug and release directories.
build_all If debug_and_release is specified, the project is built in both debug and release modes by default.
autogen_precompile_source Automatically generates a .cpp file that includes the precompiled header file specified in the .pro file.
ordered When using the subdirs template, this option specifies that the directories listed should be processed in the order in which they are given.
Note: The use of this option is discouraged. Specify dependencies as described in the SUBDIRS variable documentation.precompile_header Enables support for the use of precompiled headers in projects.
precompile_header_c (MSVC only) Enables support for the use of precompiled headers for C files.
warn_on The compiler should output as many warnings as possible. If warn_off is also specified, the last one takes effect.
warn_off The compiler should output as few warnings as possible.
exceptions Exception support is enabled. Set by default.
exceptions_off Exception support is disabled.
ltcg Link time code generation is enabled. This option is off by default.
rtti RTTI support is enabled. By default, the compiler default is used.
rtti_off RTTI support is disabled. By default, the compiler default is used.
stl STL support is enabled. By default, the compiler default is used.
stl_off STL support is disabled. By default, the compiler default is used.
thread Thread support is enabled. This is enabled when CONFIG includes qt, which is the default.
no_utf8_source Specifies that the project's source files does not use the UTF-8 encoding. Instead, the compiler default is used.
hide_symbols Set the default visibility of symbols in the binary to hidden. By default, the compiler default is used.
c99 C99 support is enabled. This option has no effect if the compiler does not support C99, or can't select the C standard. By default, the compiler default is used.
c11 C11 support is enabled. This option has no effect if the compiler does not support C11, or can't select the C standard. By default, the compiler default is used.
c17 C17, also known as C18, support is enabled. This option has no effect if the compiler does not support C17, or can't select the C standard. By default, the compiler default is used.
c18 This is an alias for the c17 value.
strict_c Disables support for C compiler extensions. By default, they are enabled.
c++11 C++11 support is enabled. This option has no effect if the compiler does not support C++11, or can't select the C++ standard. By default, support is enabled.
c++14 C++14 support is enabled. This option has no effect if the compiler does not support C++14, or can't select the C++ standard. By default, support is enabled.
c++17 C++17 support is enabled. This option has no effect if the compiler does not support C++17, or can't select the C++ standard. By default, support is enabled.
c++1z Obsolete alias for c++17.
c++20 C++20 support is enabled. This option has no effect if the compiler does not support C++20, or can't select the C++ standard. By default, support is disabled.
c++2a Obsolete alias for c++20.
c++latest Support for the latest C++ language standard is enabled that is supported by the compiler. By default, this option is disabled.
strict_c++ Disables support for C++ compiler extensions. By default, they are enabled.
depend_includepath Appending the value of INCLUDEPATH to DEPENDPATH is enabled. Set by default.
lrelease Run lrelease for all files listed in TRANSLATIONS and EXTRA_TRANSLATIONS. If embed_translations is not set, install the generated .qm files into QM_FILES_INSTALL_PATH. Use QMAKE_LRELEASE_FLAGS to add options to the lrelease call. Not set by default.
embed_translations Embed the generated translations from lrelease in the executable, under QM_FILES_RESOURCE_PREFIX. Requires lrelease to be set, too. Not set by default.
create_libtool Create a libtool .la file for the currently built library.
create_pc Create a pkg-config .pc file for the currently built library.
no_batch NMake only: Turn off generation of NMake batch rules or inference rules.
skip_target_version_ext Suppress the automatic version number appended to the DLL file name on Windows.
suppress_vcproj_warnings Suppress warnings of the VS project generator.
windeployqt Automatically invoke windeployqt after linking, and add the output as deployment items.
dont_recurse Suppress qmake recursion for the current subproject.
no_include_pwd Do not add the current directory to INCLUDEPATHS.
compile_included_sources By default, qmake does not compile source files that are included in other source files. This option disables this behavior.
When you use the debug_and_release option (which is the default under Windows), the project will be processed three times: one time to produce a "meta" Makefile, and two more times to produce a Makefile.Debug and a Makefile.Release.During the latter passes, build_pass and the respective debug or release option is appended to CONFIG. This makes it possible to perform build-specific tasks. For example:
build_pass:CONFIG(debug, debug|release) {
unix: TARGET = $$join(TARGET,,,_debug)
else: TARGET = $$join(TARGET,,,d)
}
As an alternative to manually writing build type conditionals, some variables offer build-specific variants, for example QMAKE_LFLAGS_RELEASE in addition to the general QMAKE_LFLAGS. These should be used when available.The meta Makefile makes the sub-builds invokable via the debug and release targets, and a combined build via the all target. When the build_all CONFIG option is used, the combined build is the default. Otherwise, the last specified CONFIG option from the set (debug, release) determines the default. In this case, you can explicitly invoke the all target to build both configurations at once:
make all
Note: The details are slightly different when producing Visual Studio and Xcode projects.When linking a library, qmake relies on the underlying platform to know what other libraries this library links against. However, if linking statically, qmake will not get this information unless we use the following CONFIG options:
Option Description
create_prl This option enables qmake to track these dependencies. When this option is enabled, qmake will create a file with the extension .prl which will save meta-information about the library (see Library Dependencies for more info).
link_prl When this option is enabled, qmake will process all libraries linked to by the application and find their meta-information (see Library Dependencies for more info).
no_install_prl This option disables the generation of installation rules for generated .prl files.
Note: The create_prl option is required when building a static library, while link_prl is required when using a static library.The following options define the application or library type:
Option Description
qt The target is a Qt application or library and requires the Qt library and header files. The proper include and library paths for the Qt library will automatically be added to the project. This is defined by default, and can be fine-tuned with the \l{#qt}{QT} variable.
x11 The target is an X11 application or library. The proper include paths and libraries will automatically be added to the project.
testcase The target is an automated test. A check target will be added to the generated Makefile to run the test. Only relevant when generating Makefiles.
insignificant_test The exit code of the automated test will be ignored. Only relevant if testcase is also set.
windows The target is a Win32 window application (app only). The proper include paths, compiler flags and libraries will automatically be added to the project.
console The target is a Win32 console application (app only). The proper include paths, compiler flags and libraries will automatically be added to the project. Consider using the option cmdline for cross-platform applications.
cmdline The target is a cross-platform command line application. On Windows, this implies CONFIG += console. On macOS, this implies CONFIG -= app_bundle.
shared The target is a shared object/DLL. The proper include paths, compiler flags and libraries will automatically be added to the project. Note that dll can also be used on all platforms; a shared library file with the appropriate suffix for the target platform (.dll or .so) will be created.
dll
static The target is a static library (lib only). The proper compiler flags will automatically be added to the project.
staticlib
plugin The target is a plugin (lib only). This enables dll as well.
designer The target is a plugin for Qt Designer.
no_lflags_merge Ensures that the list of libraries stored in the LIBS variable is not reduced to a list of unique values before it is used.
metatypes Create a <name>_metatypes.json file for the current project. <name> is the all lowercase base name of TARGET.
qmltypes Automatically register QML types defined in C++. For more information, see Defining QML Types from C++. Also, create a <template>.qmltypes file for the current project. <template> will be plugins (plural, for historical reasons) if plugin is set, or the value of TEMPLATE otherwise. qmltypes implies metatypes.
These options define specific features on Windows only:Option Description
flat When using the vcapp template this will put all the source files into the source group and the header files into the header group regardless of what directory they reside in. Turning this option off will group the files within the source/header group depending on the directory they reside. This is turned on by default.
embed_manifest_dll Embeds a manifest file in the DLL created as part of a library project.
embed_manifest_exe Embeds a manifest file in the EXE created as part of an application project.
See Platform Notes for more information about the options for embedding manifest files.The following options take an effect only on macOS:
Option Description
app_bundle Puts the executable into a bundle (this is the default).
lib_bundle Puts the library into a library bundle.
plugin_bundle Puts the plugin into a plugin bundle. This value is not supported by the Xcode project generator.
The build process for bundles is also influenced by the contents of the QMAKE_BUNDLE_DATA variable.The following options take an effect only on Linux/Unix platforms:
Option Description
largefile Includes support for large files.
separate_debug_info Puts debugging information for libraries in separate files.
The CONFIG variable will also be checked when resolving scopes. You may assign anything to this variable.For example:
CONFIG += console newstuff
...
newstuff {
SOURCES += new.cpp
HEADERS += new.h
}
DEFINES
qmake adds the values of this variable as compiler C preprocessor macros (-D option).For example:
DEFINES += USE_MY_STUFF
DEFINES_DEBUG
Specifies preprocessor defines for the debug configuration. The values of this variable get added to DEFINES after the project is loaded. This variable is typically set in qmake.conf and rarely needs to be modified.This variable was introduced in Qt 5.13.2.
DEFINES_RELEASE
Specifies preprocessor defines for the release configuration. The values of this variable get added to DEFINES after the project is loaded. This variable is typically set in qmake.conf and rarely needs to be modified.Note: For MSVC mkspecs, this variable contains the value NDEBUG by default.
This variable was introduced in Qt 5.13.2.
DEF_FILE
Note: This variable is used only on Windows when using the app template.Specifies a .def file to be included in the project.
DEPENDPATH
Specifies a list of directories for qmake to scan, to resolve dependencies. This variable is used when qmake crawls through the header files that you #include in your source code.DESTDIR
Specifies where to put the target file.For example:
DESTDIR = ../../lib
Note: The list of supported characters can depend on the used build tool. In particular, parentheses do not work with make.DISTFILES
Specifies a list of files to be included in the dist target. This feature is supported by UnixMake specs only.For example:
DISTFILES += ../program.txt
DLLDESTDIR
Note: This variable applies only to Windows targets.Specifies where to copy the target dll.
EXTRA_TRANSLATIONS
Specifies a list of translation (.ts) files that contain translations of the user interface text into non-native languages.In contrast to TRANSLATIONS, translation files in EXTRA_TRANSLATIONS will be processed only by lrelease, not lupdate.
You can use CONFIG += lrelease to automatically compile the files during the build, and CONFIG += lrelease embed_translations to make them available in The Qt Resource System.
See the Qt Linguist Manual for more information about internationalization (i18n) and localization (l10n) with Qt.
FORMS
Specifies the UI files (see Qt Designer Manual) to be processed by uic before compiling. All dependencies, headers and source files required to build these UI files will automatically be added to the project.For example:
FORMS = mydialog.ui
mywidget.ui
myconfig.ui
GUID
Specifies the GUID that is set inside a .vcproj file. The GUID is usually randomly determined. However, should you require a fixed GUID, it can be set using this variable.This variable is specific to .vcproj files only; it is ignored otherwise.
HEADERS
Defines the header files for the project.qmake automatically detects whether moc is required by the classes in the headers, and adds the appropriate dependencies and files to the project for generating and linking the moc files.
For example:
HEADERS = myclass.h
login.h
mainwindow.h
See also SOURCES.ICON
This variable is used only on Mac OS to set the application icon. Please see the application icon documentation for more information.IDLSOURCES
This variable is used only on Windows for the Visual Studio project generation to put the specified files in the Generated Files folder.INCLUDEPATH
Specifies the #include directories which should be searched when compiling the project.For example:
INCLUDEPATH = c:/msdev/include d:/stl/include
To specify a path containing spaces, quote the path using the technique described in Whitespace.win32:INCLUDEPATH += "C:/mylibs/extra headers"
unix:INCLUDEPATH += "/home/user/extra headers"
INSTALLS
Specifies a list of resources that will be installed when make install or a similar installation procedure is executed. Each item in the list is typically defined with attributes that provide information about where it will be installed.For example, the following target.path definition describes where the build target will be installed, and the INSTALLS assignment adds the build target to the list of existing resources to be installed:
target.path += $$[QT_INSTALL_PLUGINS]/imageformats
INSTALLS += target
INSTALLS has a .CONFIG member that can take several values:Value Description
no_check_exist If not set, qmake looks to see if the files to install actually exist. If these files don't exist, qmake doesn’t create the install rule. Use this config value if you need to install files that are generated as part of your build process, like HTML files created by qdoc.
nostrip If set, the typical Unix strip functionality is turned off and the debug information will remain in the binary.
executable On Unix, this sets the executable flag.
no_build When you do a make install, and you don't have a build of the project yet, the project is first built, and then installed. If you don't want this behavior, set this config value to ensure that the build target is not added as a dependency to the install target.
no_default_install A project has a top-level project target where, when you do a make install, everything is installed. But, if you have an install target with this config value set, it's not installed by default. You then have to explicitly say make install_<file>.
For more information, see Installing Files.This variable is also used to specify which additional files will be deployed to embedded devices.
JAVA_HOME
Note: This variable is useful only to Android targets.Specifies the JDK/OpenJDK installation path used for building the project.
LEXIMPLS
Specifies a list of Lex implementation files. The value of this variable is typically handled by qmake or qmake.conf and rarely needs to be modified.LEXOBJECTS
Specifies the names of intermediate Lex object files. The value of this variable is typically handled by qmake and rarely needs to be modified.LEXSOURCES
Specifies a list of Lex source files. All dependencies, headers and source files will automatically be added to the project for building these lex files.For example:
LEXSOURCES = lexer.l
LIBS
Specifies a list of libraries to be linked into the project. If you use the Unix -l (library) and -L (library path) flags, qmake handles the libraries correctly on Windows (that is, passes the full path of the library to the linker). The library must exist for qmake to find the directory where a -l lib is located. -
INCLUDEPATH += D:/MyLibraries/ LIBS += -LD:/MyLibraries/ -lMy3DLib
The backslash is a line breaker. There's no reason to put it within statements.
INCLUDEPATH += \ D:/MyLibraries/ LIBS += \ -LD:/MyLibraries/ \ -lMy3DLib
-
Ignore that last post I tried copying from the Qt documentation and got that mess. It stated that the -L and -l was for Unix only that you should use the full path for Windows. In my case that is d:\MyLibraries\libMy3DLib.a. It does not work when I try
LIBS =+ d:\MyLibraries\libMy3DLib.aDo I need :
INCLUDEPATH += d:/MyLibraries/libMy3DLib.Can I delete that previous reply?
-
The INCLUDEPATH variable is to add paths for the compiler to find additional includes. It has no role with regard to the linker.
-
INCLUDEPATH += D:/MyLibraries/ LIBS += -LD:/MyLibraries/ -lMy3DLib
The backslash is a line breaker. There's no reason to put it within statements.
INCLUDEPATH += \ D:/MyLibraries/ LIBS += \ -LD:/MyLibraries/ \ -lMy3DLib
-
The INCLUDEPATH variable is to add paths for the compiler to find additional includes. It has no role with regard to the linker.
-
I found the following URL
Same as my problem and another were in the .pro file you right click and get as series of dialogs that allow you to find and select the internal, in the build path can some tell me what that is, or external libraries. I choose external libraries and I finally got the following added to the .pro file:QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
CONFIG += c++11
You can make your code fail to compile if it uses deprecated APIs.
In order to do so, uncomment the following line.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
SOURCES +=
main.cpp
mainwindow.cppHEADERS +=
mainwindow.hFORMS +=
mainwindow.uiINCLUDEPATH +=
D:/MyLibraries/LIBS +=
Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += targetwin32:CONFIG(release, debug|release): LIBS += -L$$PWD/../MyLibraries/ -lMy3DLib
else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/../MyLibraries/ -lMy3DLibdINCLUDEPATH += $$PWD/../MyLibraries
DEPENDPATH += $$PWD/../MyLibrarieswin32-g++:CONFIG(release, debug|release): PRE_TARGETDEPS += $$PWD/../MyLibraries/libMy3DLib.a
else:win32-g++:CONFIG(debug, debug|release): PRE_TARGETDEPS += $$PWD/../MyLibraries/libMy3DLibd.a
else:win32:!win32-g++:CONFIG(release, debug|release): PRE_TARGETDEPS += $$PWD/../MyLibraries/My3DLib.lib
else:win32:!win32-g++:CONFIG(debug, debug|release): PRE_TARGETDEPS += $$PWD/../MyLibraries/My3DLibd.libwin32:CONFIG(release, debug|release): LIBS += -L$$PWD/../MyLibraries/ -lMy3DLib
else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/../MyLibraries/ -lMy3DLibdINCLUDEPATH += $$PWD/../MyLibraries
DEPENDPATH += $$PWD/../MyLibrariesons/1361229/using-a-static-library-in-qt-creatorThat did not work , so I added
LIBS +=
-LD:/MyLibraries/
-llibMy3DLibBut it still does not work. What am I missing?
-
Where exactly is that library located in your computer ?
-
Then why did you not use "d:/qtprograms/mylibriaries/" in your .pro file the whole time ?
-
@SGaist
INCLUDEPATH +=
D:/qtprograms/MyLibraries/LIBS += -LD:/qtprograms/MyLibraries -llibMy3DLib
I originally had the library at d:/MyLibraries but when I saw in the documentation that it should be under the same folder as the program I made the change.
If the above ,pro entries are not correct the what should they be?
-
I forget to give you the details of my computer configuration:
{noformat}
Qt 6.2.2 (x86_64-little_endian-llp64 shared (dynamic) release build; by MSVC 2019) on "windows"
OS: Windows 11 Version 2009 [winnt version 10.0.22000]Architecture: x86_64; features: SSE2 SSE3 SSSE3 SSE4.1 SSE4.2 AVX AVX2
Environment:
Features: QT_NO_EXCEPTIONS
Please note that it is Window 11 which I saw might have some plugin issues.
I hope this helps because using libraries would seem a must have for application development.
-
@SGaist
INCLUDEPATH +=
D:/qtprograms/MyLibraries/LIBS += -LD:/qtprograms/MyLibraries -llibMy3DLib
I originally had the library at d:/MyLibraries but when I saw in the documentation that it should be under the same folder as the program I made the change.
If the above ,pro entries are not correct the what should they be?
-
@ofmrew said in Using a Static Library I Created:
INCLUDEPATH += D:/qtprograms/MyLibraries/
Is this really what you have, as shown on two lines?
And similarly
LIBS += -LD:/MyLibraries/ -llibMy3DLib
?
@JonB The .pro file is:
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
CONFIG += c++11
You can make your code fail to compile if it uses deprecated APIs.
In order to do so, uncomment the following line.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
SOURCES +=
main.cpp
mainwindow.cppHEADERS +=
mainwindow.hFORMS +=
mainwindow.uiINCLUDEPATH +=
D:/qtprograms/MyLibraries/libMy3DLibLIBS += -LD:/qtprograms/MyLibraries -lMy3DLib
Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += targetwin32:CONFIG(release, debug|release): LIBS += -L$$PWD/../MyLibraries/ -lMy3DLib
else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/../MyLibraries/ -lMy3DLibdINCLUDEPATH += $$PWD/../MyLibraries
DEPENDPATH += $$PWD/../MyLibrarieswin32-g++:CONFIG(release, debug|release): PRE_TARGETDEPS += $$PWD/../MyLibraries/libMy3DLib.a
else:win32-g++:CONFIG(debug, debug|release): PRE_TARGETDEPS += $$PWD/../MyLibraries/libMy3DLibd.a
else:win32:!win32-g++:CONFIG(release, debug|release): PRE_TARGETDEPS += $$PWD/../MyLibraries/My3DLib.lib
else:win32:!win32-g++:CONFIG(debug, debug|release): PRE_TARGETDEPS += $$PWD/../MyLibraries/My3DLibd.libwin32:CONFIG(release, debug|release): LIBS += -L$$PWD/../MyLibraries/ -lMy3DLib
else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/../MyLibraries/ -lMy3DLibdINCLUDEPATH += $$PWD/../MyLibraries
DEPENDPATH += $$PWD/../MyLibrariesI think that I have tried ever combination for LIBS and INCLUDEPATH, but every time I compile I have not issues, but when I look at mainwindow.cpp i have all my includes marked as file not found.
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "vector4.h"
#include "matrix4x4.h"
#include "freefun.h"MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
{
ui->setupUi(this);
}MainWindow::~MainWindow()
{
delete ui;
}
From what I have found on the Internet I am not the only one having trouble accessing a library on the windows platform. Could win11 be the problem? -
@JonB The .pro file is:
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
CONFIG += c++11
You can make your code fail to compile if it uses deprecated APIs.
In order to do so, uncomment the following line.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
SOURCES +=
main.cpp
mainwindow.cppHEADERS +=
mainwindow.hFORMS +=
mainwindow.uiINCLUDEPATH +=
D:/qtprograms/MyLibraries/libMy3DLibLIBS += -LD:/qtprograms/MyLibraries -lMy3DLib
Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += targetwin32:CONFIG(release, debug|release): LIBS += -L$$PWD/../MyLibraries/ -lMy3DLib
else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/../MyLibraries/ -lMy3DLibdINCLUDEPATH += $$PWD/../MyLibraries
DEPENDPATH += $$PWD/../MyLibrarieswin32-g++:CONFIG(release, debug|release): PRE_TARGETDEPS += $$PWD/../MyLibraries/libMy3DLib.a
else:win32-g++:CONFIG(debug, debug|release): PRE_TARGETDEPS += $$PWD/../MyLibraries/libMy3DLibd.a
else:win32:!win32-g++:CONFIG(release, debug|release): PRE_TARGETDEPS += $$PWD/../MyLibraries/My3DLib.lib
else:win32:!win32-g++:CONFIG(debug, debug|release): PRE_TARGETDEPS += $$PWD/../MyLibraries/My3DLibd.libwin32:CONFIG(release, debug|release): LIBS += -L$$PWD/../MyLibraries/ -lMy3DLib
else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/../MyLibraries/ -lMy3DLibdINCLUDEPATH += $$PWD/../MyLibraries
DEPENDPATH += $$PWD/../MyLibrariesI think that I have tried ever combination for LIBS and INCLUDEPATH, but every time I compile I have not issues, but when I look at mainwindow.cpp i have all my includes marked as file not found.
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "vector4.h"
#include "matrix4x4.h"
#include "freefun.h"MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
{
ui->setupUi(this);
}MainWindow::~MainWindow()
{
delete ui;
}
From what I have found on the Internet I am not the only one having trouble accessing a library on the windows platform. Could win11 be the problem?