qt-creator and msvc can't add a (static) library - c++

I have a 3rd party (closed source) static library (.lib) written in C, with a C++ compatible header and a very simple C++ test program.
After creating a new project in Qt-creator, I tried to compile the program and link to the static library, but the linker cannot resolve the symbols: "Unresolved external symbol", error LNK2019.
I am using Qt 5.3 with the compiler from VisualC++ 2013 Express (which I think is MSVC12), and the .pro file used in Qt-creator is the following:
TEMPLATE = app
CONFIG += console
CONFIG -= app_bundle
CONFIG -= qt
LIBS += -L"C:/Users/myuser/myproject" -lsomelib
SOURCES += main.cpp
HEADERS += \
somelib.h
assuming that in C:\Users\myuser\myproject there are the following two files:
libsomelib.lib
somelib.h
I am not sure about what to provide in the -l flag, so I tried with libsomelib.lib, libsomelib and somelib as I would do in Linux, but every combination was unsuccessful.
This is my first time using MSVC from Qt-creator (not that I have much experience with it), so I cannot really understand the linking command issued by qt-creator, which includes manifest files that I do not know, and - apparently - no files or libraries are listed explicitly in the command:
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 /MANIFESTFILE:debug\myproject.exe.embed.manifest /OUT:debug\myproject.exe #C:\Users\myuser\AppData\Local\Temp\myproject.exe.4260.531.jom
Note that if I do not use qmake and compile this example by hand using cl and link, the program links just fine. To achieve this, I use the commands:
cl /MT /EHsc /c main.cpp
link /LIBPATH:C:\Users\myuser\myproject libsomelib.lib main.obj /out:test.exe
How can I fix that? Thanks in advance!

Somehow I managed to compile the code using MSVC.
I tried to reproduce the compilation on Qt-Creator but without success; also tried to export a qmake project from VS using the Qt Add-in, but the issue persist in qt creator. So I'm giving up and continue to use VS to compile.

Related

Adding OR-Tools Library to Visual Studio

I am trying to write a code using Google's OR-Tools library on Microsoft Visual Studio 2019. I followed the following steps:
Installed OR-Tools from Binary on Windows on their website.
Extracted the .zip file in C:\Libraries
Wrote my code on VS (I wrote #include <ortools/linear_solver/linear_solver.h> and using namespace operations_research; rest is usual C++ Code)
In Visual Studio, went to Project > Properties > C/C++ > Additional Include Directories
Added "C:\Libraries\or-tools\include" (which contains the folder "ortools" that I included)
Clicked Apply then OK then compiled my code.
I am getting a bunch of linking errors "error LINK2019". Is there anything else I should do so I can use this library freely on my machine?
From the supplied makefile:
Compile flags:
DEBUG = /O2 -DNDEBUG
CXXFLAGS = /std:c++17 /EHsc /MD /nologo /D_SILENCE_STDEXT_HASH_DEPRECATION_WARNINGS -nologo $(DEBUG) \
/DPSAPI_VERSION=1 /D__WIN32__ /DNOMINMAX /DWIN32_LEAN_AND_MEAN=1 /D_CRT_SECURE_NO_WARNINGS \
/DGFLAGS_DLL_DECL= /DGFLAGS_DLL_DECLARE_FLAG= /DGFLAGS_DLL_DEFINE_FLAG= /DGOOGLE_GLOG_DLL_DECL= \
/I$(INC_DIR)\\src\\windows /I$(INC_DIR) /I. \
/DUSE_BOP /DUSE_GLOP \
/DUSE_CBC /DUSE_CLP \
/DUSE_SCIP
Link flags:
LDFLAGS = psapi.lib ws2_32.lib
OR_TOOLS_LNK = lib\\ortools.lib

Compiling FFmpeg with Libass using MSVC

First a bit of background.
I'm trying to compile ffmpeg on windows with the libass extensions/configuration option.
Using the visual studio project libass-msvc I built libass using Visual Studio as a static lib.
I then installed MinGW with MSYS and pkg-config. Following the instructions on the ffmpeg MSVC installation guide I configured the environment to build with the MSVC linker and to build in x64.
When I try to configure libass for compilation using ./configure --enable-libass --toolchain=msvc I get the following error in the log file:
File not found ass/ass.h
pkg-config can not find libass
I have tried the following to fix this.
Create a .pc file for libass and add this to the PKG_CONFIG_PATH environment variable. See file content below. (After doing this pkg-config libass --version prints 0.81, not the right version number but at least something.)
Copy libass .h files into a MinGW/include/ass folder and the .lib file into the MinGW/libs folder.
Add libass include and bin folders to PATH environment variable
Download libass and dependencies source then try to build it using MSYS with MSVC compiler. My aim here was to be able to use "make install" and let MinGW install libass to the correct locations. After hours of trying to fix linker errors, I abandoned this idea as some of the libass dependencies make files only work with the GCC GNU compiler.
Compile libass with GCC GNU using MinGW make/make install then try and install libass using the GNU libs. Again this led to linker errors (I know this was a bad idea but was worth a try).
Tried using extra lib and include build configuration options --extra-cflags="ffmpeg-dir/extra/include" \
--extra-ldflags="ffmped-dir/extra/ffmpeg_build/lib" then adding the libs and .h files into those locations
.pc file
libass.pc:
prefix=/MinGW
includedir=libass-directory/include
libdir=libass-director/x64/bin/
Name: libass
Description: Libass project
Version: 0.13.7
I am now completely stuck and out of ideas if anyone could give any insight or suggestions into what I'm doing wrong that would be fantastic.
Update
I created INCLUDE and LIBDIR environment path variable containing the libass paths. Which now correctly includes libass. However, I now get the following linker error for the function check_ass_library_init.
check_func_headers ass/ass.h ass_library_init
check_ld cc
check_cc
BEGIN ./ffconf.RZMYFWdc/test.c
1 #include
2 #include
3 long check_ass_library_init(void) { return (long)
ass_library_init; }
4 int main(void) { int ret = 0;
5 ret |= ((intptr_t)check_ass_library_init) & 0xFFFF;
6 return ret; }
END ./ffconf.RZMYFWdc/test.c
cl -D_ISOC99_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -
D_USE_MATH_DEFINES -D_CRT_SECURE_NO_WARNINGS -D_CRT_NONSTDC_NO_WARNINGS -
D_WIN32_WINNT=0x0502 -nologo -c -Fo./ffconf.RZMYFWdc/test.o
./ffconf.RZMYFWdc/test.c
test.c
./ffconf.RZMYFWdc/test.c(3): warning C4311: 'type cast': pointer truncation
from 'ASS_Library *(__cdecl *)(void)' to 'long'
./compat/windows/mslink -nologo -out:./ffconf.RZMYFWdc/test.exe
./ffconf.RZMYFWdc/test.o psapi.lib advapi32.lib shell32.lib ole32.lib
test.o : error LNK2019: unresolved external symbol ass_library_init
referenced in function check_ass_library_init
./ffconf.RZMYFWdc/test.exe : fatal error LNK1120: 1 unresolved externals
ERROR: libass not found using pkg-config
The libass test project which uses ass_library_init compiles fine using the same lib files, the libs appear to be fine.
From what I see from this line "./compat/windows/mslink -nologo -out:./ffconf.RZMYFWdc/test.exe ./ffconf.RZMYFWdc/test.o psapi.lib advapi32.lib shell32.lib ole32.lib" libass is not being passed to the linker.
I suspect that the configuration file is not creating the link to libass in the make file when compiling with MSVC.
Am I correct or am I going about compiling this in the wrong way?

Failed to link openssl to Qt

I have started a project with Qtcreator on linux. This project uses the Openssl library to work.
So In my .pro file I have added theses lines :
LIBS += -lssl
LIBS += -lcrypto
So on linux it works perfectly.
But, I have to continue my project on windows. I had to install Openssl with cygwin, I have chosen this package : "cygwin32-openssl-1.0.1e-1.tar.bz2" because I compile in 32bits.
I have created a sub-repertory, named libs, in my program folder and I put the three openssl folders (bin, include and lib) in my "libs" repertory.
The content of the lib directory is :
libcrypto.a
libcrypto.dll.a
libssl.a
libssl.dll.a
pkgconfig/libcrypto.pc
pkgconfig/libssl.pc
pkgconfig/openssl.pc
In the bin directory I have 2 .dll, cygcrypto-1.0.0.dll and cygssl-1.0.0.dll
I added in my .pro file these lines :
LIBS += -lssl
LIBS += -lcrypto
LIBS += -L"$$PWD/libs/openssl/lib/"
INCLUDEPATH += $$PWD/libs/openssl/include/
If I change -L"$$PWD/libs/openssl/lib/" by -L"$$PWD/libs/openssl/bin/", the compilator don't recognized the -lssl and -lcrypto options.
QtCreator recognized the headers files (for example ) and when I compile, no error occurred.
But when I launch my program, it doesn't work and no error appears.
So I put a breaking point at the begining of my main function, and I re-launch the program. After that a little window indicates to me this error :
Executable failed: During startup program exited with code 0xc0000135
I use Qt 5.4.0 and Mingw 32bits
I don't undertsand why it doesn't work. Can you help me please ?
Thank you.
The entirety of your project needs to use cygwin, or none of it. Since I assume you're compiling using a Visual Studio compiler, you'll need to use an OpenSSL build that isn't cygwin-dependent. For example, the one from Shining Light Productions, the de-fact OpenSSL binary purveyor for Windows.

Building a wxWidgets program in Code::Blocks

I'm trying to build this wxWidgets sample program using Code::Blocks 12.11 but the build fails no matter what I try.
For example, the build log shows the following (the project is under X:\programming\c++\HelloWxWidgets):
mingw32-g++.exe -Wall -fexceptions -g -D_GNUWIN32_ -D_WXMSW_ -DwxUSE_UNICODE -D_WXDEBUG_ -IC:\libraries\wxWidgets-2.8.12.01\include -IC:\libraries\wxWidgets-2.8.12.01\contrib\include -IC:\libraries\wxWidgets-2.8.12.01\lib\gcc_lib\mswud -c X:\programming\c++\HelloWxWidgets\hworld2.cpp -o obj\Debug2\hworld2.o
mingw32-g++.exe -LC:\libraries\wxWidgets-2.8.12.01\lib\gcc_lib -o bin\Debug2\HelloWxWidgets.exe obj\Debug2\hworld2.o -static-libgcc C:\libraries\wxWidgets-2.8.12.01\lib\gcc_lib\libwxmsw28ud.a
C:\libraries\wxWidgets-2.8.12.01\lib\gcc_lib\libwxmsw28ud.a(monolib_window.o): In function ZN8wxWindow6UpdateEv':
C:\BuildAgent\work\wxPack\wxwidgets\build\msw/../../src/msw/window.cpp:1643: undefined reference toGdiFlush#0'
C:\libraries\wxWidgets-2.8.12.01\lib\gcc_lib\libwxmsw28ud.a(monolib_window.o): In function ZNK8wxWindow13GetTextExtentERK8wxStringPiS3_S3_S3_PK6wxFont':
C:\BuildAgent\work\wxPack\wxwidgets\build\msw/../../src/msw/window.cpp:2132: undefined reference toGetTextExtentPoint32W#16'
C:\BuildAgent\work\wxPack\wxwidgets\build\msw/../../src/msw/window.cpp:2133: undefined reference to `GetTextMetricsW#8'
And these are some of the build messages that I get
C:\libraries\wxWidgets-2.8.12.01\lib\gcc_lib\libwxmsw28ud.a(monolib_window.o)||In function ZN8wxWindow6UpdateEv':|
C:\BuildAgent\work\wxPack\wxwidgets\build\msw\..\..\src\msw\window.cpp|1643|undefined reference toGdiFlush#0'|
C:\libraries\wxWidgets-2.8.12.01\lib\gcc_lib\libwxmsw28ud.a(monolib_window.o)||In function ZNK8wxWindow13GetTextExtentERK8wxStringPiS3_S3_S3_PK6wxFont':|
C:\BuildAgent\work\wxPack\wxwidgets\build\msw\..\..\src\msw\window.cpp|2132|undefined reference toGetTextExtentPoint32W#16'|
C:\BuildAgent\work\wxPack\wxwidgets\build\msw....\src\msw\window.cpp|2133|undefined reference to `GetTextMetricsW#8'|
Here are the full build log and all of the build messages (by the way, I don't have a C:\BuildAgent directory)
I am using wxPack 2.8.12 (installed in C:\libraries\wxWidgets-2.8.12.01) and GCC 4.7.2 (installed separately from Code::Blocks in C:\mingw using mingw-get )
Here are the build options in Code::Blocks
compiler settings > defines
linker settings
search directories > compiler
search directories > linker
search directories > resource compiler
Thank you in advance of your help :)
Alright, I finally managed to get it working :)
I'm posting here the procedure to follow if, like me, someone wanted to use wxWidgets in an (initially) console project under Code::Blocks. With this, anyone should be able to build/run at least this sample code in a Wind0ws environment:
I'll assume that Code::Blocks and MinGW are correctly setup.
Download/Install wxMSW from http://www.wxwidgets.org/downloads/ (in my case, I downloaded wxMSW-2.8.12-Setup.exe and installed it in C:\libraries\wxWidgets-2.8.12)
Open a command prompt, wxWidgets needs to be built, I'll take the exemple of a statically-linked, monolithic, debug build that uses unicode (more infos here):
cd /D C:\libraries\wxWidgets-2.8.12\build\msw
mingw32-make -f makefile.gcc BUILD=debug SHARED=0 MONOLITHIC=1 UNICODE=1
:(mingw32-make will take some time to build the library)
Open Code::Blocks
Create a new console project, or if you already have a console project (and you plan to add a wxWidgets GUI to it) open it
Right-click on the project > Build options
Here are the build options that I used for the Debug build.
Build & Run
[EDIT] wx/app.h should be included in addition to wx/wx.h
#include <wx/wx.h>
#include <wx/app.h>
You probably need to add following libs to linker settings (I took the list from VS 2012 but for GCC should be the same, you will need to add -luuid -luser32 .... to linker advanced options)
kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib
advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib
odbccp32.lib
UPD: can see taht chris suggested to add gdi32 lib. Looks reasonable for me. At least missing functions from your logs are defined there.
I found a best way is that add ``wx-config --libs all` in your "other liner options" ,On this ,many issue will gone.
wxconfig screen shot

How to link against a static library which uses static libraries itself using scons and Visual C++?

My SConstruct file looks something like this:
jnglLibs = Split("freetype png ogg vorbisfile") # left out a few
env.Library(target="jngl", source=source_files, LIBS=jnglLibs)
env.Program("test.cpp", LIBS=Split("jngl") + jnglLibs)
The static library links fine but the program fails with unresolved external symbols from the libraries in jnglLibs.
lib /nologo /OUT:jngl.lib finally.obj freetype.obj main.obj opengl.obj sprite.ob
j tess.obj texture.obj window.obj windowptr.obj callbacks.obj ConvertUTF.obj aud
io.obj win32\message.obj win32\time.obj win32\window.obj
cl /Fotest.obj /c test.cpp /TP /nologo /EHsc /MD -O2 -DNDEBUG /I.
test.cpp
link /OUT:test.exe /LIBPATH:. /LIBPATH:lib jngl.lib freetype.lib png.lib opengl3
2.lib glu32.lib user32.lib shell32.lib gdi32.lib z.lib jpeg.lib dl.lib openal32.
lib alut.lib ogg.lib vorbisfile.lib test.obj
Microsoft (R) Incremental Linker Version 10.00.30319.01
Copyright (C) Microsoft Corporation. All rights reserved.
jngl.lib(freetype.obj) : error LNK2019: unresolved external symbol FT_Done_FreeT
ype referenced in function "public: __cdecl jngl::Font::~Font(void)" (??1Font#jn
gl##QEAA#XZ)
... and so on
Why doesn't it find the symbol FT_Done_FreeType which is in freetype.lib? It works perfectly with GCC.
There are a lot of quirks with static linking on Windows.. I've had one or two similar problems to this but mostly my problem was once the 'static' libs were compiled they still depended on the .dll's being there. Anyway, I've been feeling your pain for a while now but got through it for my purposes... here's one page that really helped me.
http://xmlsoft.org/XSLT/tutorial2/libxslt_pipes.html#windows-build
It doesn't have to do with those particular libraries you listed but it might give you some clues. One thing is figuring out which C-runtime library each of those .libs (or '_a.libs,' which you might want to look into) were compiled against and make sure they are all the same when you statically link. So since you're using /MD, make sure all those libs were also compiled with /MD and not /MT. That COULD be a reason it isn't finding that freetype symbol, but it's just one guess. Good luck!