QT 打包
找到生成的exe,根据build工具从开始菜单选择:
cd到exe目录,执行:
windeployqt 目标.exe
QT Cmake 无控制台
修改CMakeLists.txt加上WIN32:
add_executable(untitled
WIN32
main.cpp
mainwindow.cpp
mainwindow.h
mainwindow.ui
)
另外QMake的*.pro文件默认是这样的:
TEMPLATE = app
CONFIG += console
CONFIG -= app_bundle
CONFIG -= qt
SOURCES += main.cpp
我们只需要把”CONFIG += console“注释掉即可。
MinGW gcc 调用dll
//mydll.h
#ifndef _MY_DLL_H
# define _MY_DLL_H_
#ifdef __cplusplus
extern "C" {
#endif
extern __declspec (dllexport) int add_range (int, int);
extern __declspec (dllexport) double average (int*, int);
#ifdef __cplusplus
}
#endif
#endif // ~_MY_DLL_H_
//mydll.c
#include "mydll.h"
// __declspec (dllexport)
int add_range (int _sta, int _end) {
int res = 0;
if (_sta > _end)
return 0x7fffffff;
for (; _sta != _end; _sta ++) {
res += _sta;
}
return res;
}
// __declspec (dllexport)
double average (int* _arr, int _cnt) {
double res = 0.0;
int i = 0;
if (_cnt <= 0)
return (double) (~0);
for (; i < _cnt; i ++)
res += _arr [i];
return (double) (res /= _cnt);
}
//先编译成目标文件:
gcc -m32 -c mydll.c
//再连接成dll:
gcc -m32 -shared -o mydll.dll mydll.o
//test.c
#include <stdio.h>
#include "mydll.h"
int main (int argc, char* argv []) {
int res = add_range (10, 200);
printf ("%d\n", res);
return 0;
}
//调用dll编译
gcc -m32 -o test.exe test.c mydll.dll