Run QT GUI via lib and dll on console application? - visual-studio

Downloadable address of full source code:
http://cfile209.uf.daum.net/attach/267EAF4B5215CFDD0D951E
Hi. I am trying to create a console application which use a function coded in a lib file, which also call functions in a dll file. (console -> lib -> dll)
Dll file is QT Gui implementation.
Lib file loads things from DLL using QLibrary.
Those lib and dll library are compiled on QT Creator via .pro file. (QT version is latest 5)
The Main console applications uses those two lib and dll is created on MSVS 2008.
Here I got an error when I compile it on MSVS 2008:
1>main.obj : error LNK2019: unresolved external symbol "int __cdecl CreateQt(int,char * * const)" (?CreateQt##YAHHQAPAD#Z) referenced in function _main
I put lib and dll into Console application's folder, it seem like I get an linking error, any help?
Thank you
Here is my console application source code.
#include "main.h"
#pragma comment(lib,"./main.lib") //main.lib is library created on QT Creator
int main(int argc, char *argv[])
{
CreateQt(argc,argv);
return 0;
}

Do you have
TEMPLATE = lib
In your lib's pro file?
In your console's pro file do you have something like
LIBS += -L../folder/path/to/libfile -lLibFileNameWithoutDotLib
It seems like you're not linking the lib file in your console app correctly. I assume that CreateQt is a function you have in your lib code.

Related

Qt Windows application linker error: unresolved symbol _WinMain

I am building a Windows application based on Qt using VisualStudio 2017 Professional (15.9.35) and the Qt VS Tools add-on. The project compiled fine up to a certain point, now the linker gives the error:
10>MSVCRTD.lib(exe_winmain.obj) : error LNK2019: unresolved external symbol _WinMain#16 referenced in function "int __cdecl invoke_main(void)" (?invoke_main##YAHXZ)
The target Qt version is Qt-5.12.10-msvc2017-32 (my application is 32-bit). My application defines main(), I expect WinMain to be defined by Qt which in turn will call my main() (as stated here, it worked at earlier stages of the development)
What I've checked (in the project for the application, and also in the dependency libraries project that are in the same VS solution):
Qt modules: core;gui;testlib;widgets
Subsystem: Windows (/SUBSYSTEM:WINDOWS)
Character Set: blank (it's not either "Not set", it's set that way by the Qt VS Tools add-on when first creating a project)
Treat wchar_t as built-in type: Yes (/Zc:wchar_t)

MSVC fatal error LNK1120: 1 unresolved externals with FFMPEG libs

I am trying to utilize the ffmpeg libraries in a program of my own and am having trouble linking them. Specifically, In my a basic program I am receiving fatal error LNK1120: 1 unresolved externals errors. The program is:
#include <iostream>
#include <libswresample/swresample.h>
int main()
{
std::cout << "Hello World!\n";
struct SwrContext* swr_ctx = swr_alloc();
if (!swr_ctx) {
std::cout << "Could not allocate resampler context";
}
}
I downloaded prebuild libraries from https://ffmpeg.zeranoe.com/builds/, specifically the Windows x64 dev package which includes the .def/.lib as well as .dll files.
I originally tried (and intend to ultimately use) cmake to generate the MSVC sln files. The cmake file is:
cmake_minimum_required(VERSION 3.5)
project(ffmpeg_jni)
# Find the JNI bits
find_package(JNI)
# Search for the ffmpeg libraries
set(ffmpeg_include_hint "ffmpeg-dev/include")
set(ffmpeg_lib_hint "ffmpeg-dev/lib")
find_path(SWRESAMPLE_INCLUDE_DIR libswresample/swresample.h PATHS ${ffmpeg_include_hint})
find_library(SWRESAMPLE_LIBRARY swresample PATHS ${ffmpeg_lib_hint})
add_library(swresample SHARED IMPORTED)
set_target_properties(swresample PROPERTIES
IMPORTED_LOCATION "${SWRESAMPLE_LIBRARY}"
IMPORTED_IMPLIB "${SWRESAMPLE_LIBRARY}"
INTERFACE_INCLUDE_DIRECTORIES "${SWRESAMPLE_INCLUDE_DIR}"
)
# Setup basic include dirs
set(includeDIRS
src/main/cpp
${JAVA_INCLUDE_PATH})
# Setup windows specific includes
set(includeDIRS
${includeDIRS}
${JAVA_INCLUDE_PATH}/Win32)
include_directories(${includeDIRS})
set(WRAPPER_SRC
src/main/cpp/logging.c
src/main/cpp/logging.h
src/main/cpp/main.cpp)
add_library(ffmpeg_jni SHARED ${WRAPPER_SRC})
target_link_libraries(ffmpeg_jni PRIVATE swresample)
The generated solution compiles and has proper access to the include files (Visual Studio can even take me to the declarations). The issue comes in the linking phase of the build where I receive:
error LNK2019: unresolved external symbol "struct SwrContext * __cdecl
swr_alloc(void)" (?swr_alloc##YAPEAUSwrContext##XZ) referenced in
function main
Thinking that I perhaps had something wrong in cmake since I am still pretty new with it I tried making a simple demo as a pure visual studio project following what I have found in countless online demos for adding an external library to a project. Specifically this included:
Adding the directory containing the header files to Properties->C/C++->General->Additional Include Directories
Adding the directory containing the .lib files to Properties->Linker->General->Additional Library Directories (Note that the cmake path did not do this but instead added the lib file via a relative path)
Adding the .lib file to Properties->Linker->Input->Additional Dependencies
At this point any searching efforts I undertake show me different people doing the same things which tells me I've been looking at this too long to find the answer myself and its something trivial that I'm missing/not understanding.
If you are compiling your project as c++, then include FFmpeg headers as below which tells your c++ compiler to handle FFmpeg headers as C instead of C++.
extern "C" {
#include <libswresample/swresample.h>
}

Q_OBJECT Problem in Visual C++

I have received a Visual C++ QT based project from our customer. I have installed QT libraries then I have compiled the project. The Project was compiled without any problems.
Now, I need to include a new additional GUI interface with the existing project. I have created a GUI in QT designer then saved in the source directory of VC++ project. Then I have written .h and .cpp file for new GUI and could call this interface. Now I need to include SIGNALS and SLOTS, when I include Q_OBJECT in .h file. I have compilation error.
These are the errors, please help me to solve this problem:
unresolved external symbol "public: virtual struct QMetaObject const * __thiscall BetaLineServer::metaObject(void)const " (?metaObject)
unresolved external symbol "public: virtual void * __thiscall BetaLineServer::qt_metacast(char const *)"
unresolved external symbol "public: virtual int __thiscall BetaLineServer::qt_metacall(enum QMetaObject::Call,int,void * *)" (?qt_metacall#
Any time you add a Q_OBJECT macro to a class you need to be sure to rerun qmake and then compile.
All you need is to compile the header files with moc that contain Q_OBJECT macro. And how to do that? here it is
You can manually type commands for compiling moc or uic files OR
-> Install Qt-VS addin. http://qt.nokia.com/downloads/visual-studio-add-in
-> Now, open visual studio and create a new Qt project as described in here and then
-> Right click on a header file that contains the Q_OBJECT macro you should find something like below. Copy these commands into your project.
-> Replace the header file name with yours in the 'Command Line' command
-> compile once and that should generate moc_xxxxx.cpp files, include them in your project.
For future reference, if you create a Qt project in VS using this plugin you should have these commands automatically added
You probably just need to add your .ui, .cpp and .h files to the project file.
Qt will run 'moc' on the ui file if it's listed there, which creates source code to supply your missing symbols.
Exclude .h file from the project and include it again - moc_.cpp will appear in the "Generated Files", and linking errors are disapeared.

Having problems linking with v8 on windows

I'm using Visual Studio 2010 on a 64-bit Windows 7 machine. I've pulled v8 source from SVN, built it with no problems (wich arch=x64), but I still can't compile my project that tries to use v8.
Here is a sample code that produces that same error :
#include <v8.h>
int main(int argc, char *argv[])
{
v8::Handle<v8::Context> context = v8::Context::New();
return 0;
}
The linker error I get is :
v8test.obj : error LNK2019: unresolved external symbol "public: static class v8::Persistent<class v8::Context> __cdecl v8::Context::New(class v8::ExtensionConfiguration *,class v8::Handle<class v8::ObjectTemplate>,class v8::Handle<class v8::Value>)" (?New#Context#v8##SA?AV?$Persistent#VContext#v8###2#PAVExtensionConfiguration#2#V?$Handle#VObjectTemplate#v8###2#V?$Handle#VValue#v8###2##Z) referenced in function _main
I built v8 as a static lib, tried both debug and release build, I get the same error.
In addition to v8_base.lib you need to also include v8_snapshot.lib, ws2_32.lib, and winmm.lib.
The sample on the V8 Getting Started Page can be compiled in a Console Application with following dependencies listed under Project Properties->Configuration Properties->Linker->Input->Additional Dependencies:
v8_base.lib;v8_snapshot.lib;ws2_32.lib;winmm.lib;(AdditionalDependencies)

visual studio 2008 linker error

In visual studio 2008, I have created a static dll called test_static.dll. I am trying to call this from one application. I have included this dll in source files folder and the header file related to it in headers folder. When i am running the application I am getting following liking error. Please give me a solution.
error LNK2019: unresolved external
symbol "struct morph_output * __cdecl
morpho_data(struct morph_input *)"
(?morpho_data##YAPAUmorph_output##PAUmorph_input###Z)
referenced in function _wmain
1>D:\test_app\Debug\test_app.exe :
fatal error LNK1120: 1 unresolved
externals 1>Build log was saved at
"file://d:\test_app\test_app\Debug\BuildLog.htm"
Here test_app is application that is using static dll. and morpho_data is the dll function which is taking input as structure and returning another structure.
When compiling the dll you need to create an import library - a .lib file (Linker->Advanced->Import Library) and include it into the list of libraries your .exe depends on (Linker->Input->Additional Dependencies and Linker->General->Additional Library Directories).
Did you add test_static.lib as input to the linker in the project settings?
Did you include the header file where the function is declared ?

Resources