从应用程序调用静态库时,QT创建者什么都不会发生
Qt Creator Nothing happen when call a static library from an application
qt creator从应用程序调用静态库时什么都不会发生。我将这些代码线作为我的主。CPP主应用程序:
#include "mainwindow.h"
#include <QApplication>
#include<src/main.cpp>
#include <src/john.cpp>
int main(int argc, char *argv[])
{
//John ll;
main2;
// QApplication a2(argc, argv);
// MainWindow w2;
// w2.show();
// MainWindow mainWindow;
// //mainWindow.parseCmdLine(); //modified
// // mainWindow.show();
// return a2.exec();
//return 1;
}
那是.pro文件:
#-------------------------------------------------
#
# Project created by QtCreator 2017-12-08T05:51:54
#
#-------------------------------------------------
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = untitled
TEMPLATE = app
SOURCES += main.cpp
mainwindow.cpp
HEADERS += mainwindow.h
FORMS += mainwindow.ui
INCLUDEPATH += ../application
LIBS += -L../application/release/ -lApplication
#TARGET = ../app17-exe # move executable one dire up
和我的main2.cpp静态库文件如下:
/*****************************************************************************
* *
* Elmer, A Finite Element Software for Multiphysical Problems *
* *
* Copyright 1st April 1995 - , CSC - IT Center for Science Ltd., Finland *
* *
* This program is free software; you can redistribute it and/or *
* modify it under the terms of the GNU General Public License *
* as published by the Free Software Foundation; either version 2 *
* of the License, or (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program (in file fem/GPL-2); if not, write to the *
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, *
* Boston, MA 02110-1301, USA. *
* *
*****************************************************************************/
/*****************************************************************************
* *
* ElmerGUI main *
* *
*****************************************************************************
* *
* Authors: Mikko Lyly, Juha Ruokolainen and Peter Råback *
* Email: Juha.Ruokolainen@csc.fi *
* Web: http://www.csc.fi/elmer *
* Address: CSC - IT Center for Science Ltd. *
* Keilaranta 14 *
* 02101 Espoo, Finland *
* *
* Original Date: 15 Mar 2008 *
* *
*****************************************************************************/
//#include "mainwindow.h"
//#include <QApplication>
//#include<src/main.cpp>
//int main(int argc, char *argv[])
//{
//main2;
// return a.exec();
//}
#include <QApplication>
//#include <iostream>
#include "mainwindow.h"
using namespace std;
/*
#ifdef __APPLE__
#include <mach-o/dyld.h>
#include <stdlib.h>
#endif
int main2(int argc, char *argv[])
{
MainWindow mainWindow2;
//mainWindow.parseCmdLine(); //modified
mainWindow2.showFullScreen();
#ifdef __APPLE__
// we'll change ENVIRONMENT so that the Elmer binaries and libraries
// hidden wihtin the application bundle will be correctly found
char executablePath[MAXPATHLENGTH] = {0};
uint32_t len = MAXPATHLENGTH;
if(! _NSGetExecutablePath( (char*) executablePath, &len)){
// remove executable name from path:
*(strrchr(executablePath,'/'))=' ';
char *oldValue = 0, *newValue = 0;
oldValue = getenv("PATH");
asprintf(&newValue, "%s/../bin:%s",executablePath,oldValue);
setenv("PATH",newValue,1);
free(newValue);
oldValue = getenv("DYLD_LIBRARY_PATH");
asprintf(&newValue,"%s/../lib:%s",executablePath,oldValue);
setenv("DYLD_LIBRARY_PATH",newValue,0);
free(newValue);
asprintf(&newValue,"%s/..",executablePath);
setenv("ELMER_HOME",newValue,0);
free(newValue);
asprintf(&newValue,"%s/../share/elmerpost",executablePath);
setenv("ELMER_POST_HOME",newValue,0);
free(newValue);
#ifdef DEBUG
printf("PATH = %snDYLD_LIBRARY_PATH=%snELMER_HOME=%sn",
getenv("PATH"),
getenv("DYLD_LIBRARY_PATH"),
getenv("ELMER_HOME"));
#endif
}
#endif
//========================================================================
QApplication app(argc, argv);
QStringList argList = QCoreApplication::arguments();
cout << "Usage:" << endl;
if(argList.contains("-h") || argList.contains("--help")) {
cout << "Usage:" << endl;
cout << " ElmerGUI [OPTION [FILE|DIR]]..." << endl;
cout << endl;
cout << "Graphical user interface and mesh generator for Elmer" << endl;
cout << endl;
cout << "Application options:" << endl;
cout << " -h, --help Show help options" << endl;
cout << " -i <string> Select input file" << endl;
cout << " -o <string> Select output dir" << endl;
cout << " -nogui Disable GUI" << endl;
cout << " -e Exit after saving" << endl;
cout << endl;
return 0;
}
MainWindow mainWindow;
//mainWindow.parseCmdLine(); //modified
mainWindow.showFullScreen();
QApplication a(argc, argv);
MainWindow w;
w.show();
printf("sss");
char o;
scanf("%c",o);
// return a.exec();
// return app.exec();
return 900;
}
*/
int main2(int argc, char *argv[])
{
//John ll;
//main2;
QApplication a2(argc, argv);
MainWindow w2;
w2.show();
// MainWindow mainWindow;
//mainWindow.parseCmdLine(); //modified
// mainWindow.show();
return a2.exec();
//return 1;
}
是.pro文件:
#==============================================================================
#
# ElmerGUI: qmake project file for Unix, Win32, and MacX
#
#==============================================================================
include(../ElmerGUI.pri)
#------------------------------------------------------------------------------
# Target:
#------------------------------------------------------------------------------
TARGET = Application
TEMPLATE = app
CONFIG += release
#------------------------------------------------------------------------------
# Installation directory and files:
#------------------------------------------------------------------------------
target.path = $${ELMERGUI_HOME}
INSTALLS += target
edf.path = $${ELMERGUI_HOME}/edf
edf.files = edf/*
INSTALLS += edf
edf-extra.path = $${ELMERGUI_HOME}/edf-extra
edf-extra.files = edf-extra/*
INSTALLS += edf-extra
#------------------------------------------------------------------------------
# Compiler flags:
#------------------------------------------------------------------------------
#CONFIG += warn_off
#QMAKE_LFLAGS += -Wl,-rpath,$$(VTKHOME)/lib/vtk-5.2
#win32 {
# QMAKE_LFLAGS += /NODEFAULTLIB:library
#}
TEMPLATE = lib
CONFIG += staticlib
#CONFIG += warn_off
QMAKE_LFLAGS += -Wl,-rpath,$$(VTKHOME)/lib/vtk-5.2
win32 {
QMAKE_LFLAGS += /NODEFAULTLIB:library
}
#win32 {
# TARGET = test
# LIBS += -lliba.lib
# libb.lib
#
# CONFIG(release, debug|release){
# QMAKE_LFLAGS += /NODEFAULTLIB:libcmt
# }
# CONFIG(debug, debug|release){
# QMAKE_LFLAGS += /NODEFAULTLIB:libcmtd
# }
#}
QMAKE_CXXFLAGS_DEBUG += -g
QMAKE_CXXFLAGS += -g
#------------------------------------------------------------------------------
# Directories:
#------------------------------------------------------------------------------
DEPENDPATH += . src forms plugins vtkpost cad twod
INCLUDEPATH += .
MOC_DIR = tmp
OBJECTS_DIR = tmp
RCC_DIR = tmp
UI_DIR = tmp
DESTDIR = .
#------------------------------------------------------------------------------
# QT:
#------------------------------------------------------------------------------
QT += opengl xml script
CONFIG += uitools
QT+=uitools
#------------------------------------------------------------------------------
# MATC (see ../matc/README for more details):
#------------------------------------------------------------------------------
contains(DEFINES, EG_MATC) {
LIBPATH += ../matc/lib
LIBS += -lmatc
}
#------------------------------------------------------------------------------
# NETGEN (see ../netgen/README for more details):
#------------------------------------------------------------------------------
INCLUDEPATH += ../netgen/libsrc/interface
LIBPATH += ../netgen/ngcore
LIBS += -lng
#------------------------------------------------------------------------------
# QWT:
#------------------------------------------------------------------------------
contains(DEFINES, EG_QWT) {
INCLUDEPATH += $${QWT_INCLUDEPATH}
LIBPATH += $${QWT_LIBPATH}
LIBS += $${QWT_LIBS}
}
#------------------------------------------------------------------------------
# VTK:
#------------------------------------------------------------------------------
contains(DEFINES, EG_VTK) {
INCLUDEPATH += $${VTK_INCLUDEPATH}
LIBPATH += $${VTK_LIBPATH}
LIBS += $${VTK_LIBS}
}
#------------------------------------------------------------------------------
# OpenCASCADE:
#------------------------------------------------------------------------------
contains(DEFINES, EG_OCC) {
contains(BITS, 64): DEFINES += _OCC64
unix: DEFINES += HAVE_CONFIG_H HAVE_IOSTREAM HAVE_FSTREAM HAVE_LIMITS_H
win32: DEFINES += WNT CSFDB
macx: DEFINED -= EG_OCC # not supported at the moment
INCLUDEPATH += $${OCC_INCLUDEPATH}
LIBPATH += $${OCC_LIBPATH}
LIBS += $${OCC_LIBS}
}
#------------------------------------------------------------------------------
# PYTHONQT (see ../PythonQt/README for more details):
#------------------------------------------------------------------------------
contains(DEFINES, EG_PYTHONQT) {
INCLUDEPATH += $${PY_INCLUDEPATH} ../PythonQt/src
LIBPATH += $${PY_LIBPATH} ../PythonQt/lib
LIBS += $${PY_LIBS} -lPythonQt
}
#------------------------------------------------------------------------------
# Process info query on win32:
#------------------------------------------------------------------------------
win32: LIBS += -lpsapi
#------------------------------------------------------------------------------
# OpenGL GLU
#------------------------------------------------------------------------------
unix: LIBS += -lGLU
#------------------------------------------------------------------------------
# Input files:
#------------------------------------------------------------------------------
HEADERS += src/bodypropertyeditor.h
src/boundarydivision.h
src/boundarypropertyeditor.h
src/checkmpi.h
src/dynamiceditor.h
src/edfeditor.h
src/egini.h
src/generalsetup.h
src/glcontrol.h
src/glwidget.h
src/helpers.h
src/mainwindow.h
src/materiallibrary.h
src/maxlimits.h
src/meshcontrol.h
src/meshingthread.h
src/meshtype.h
src/meshutils.h
src/operation.h
src/parallel.h
src/projectio.h
src/sifgenerator.h
src/sifwindow.h
src/solverparameters.h
src/summaryeditor.h
plugins/egconvert.h
plugins/egdef.h
plugins/egmain.h
plugins/egmesh.h
plugins/egnative.h
plugins/egtypes.h
plugins/egutils.h
plugins/elmergrid_api.h
plugins/nglib_api.h
plugins/tetgen.h
plugins/tetlib_api.h
twod/renderarea.h
twod/twodview.h
twod/curveeditor.h
src/john.h
FORMS += forms/bodypropertyeditor.ui
forms/boundarydivision.ui
forms/boundarypropertyeditor.ui
forms/generalsetup.ui
forms/glcontrol.ui
forms/materiallibrary.ui
forms/meshcontrol.ui
forms/parallel.ui
forms/solverparameters.ui
forms/summaryeditor.ui
SOURCES += src/bodypropertyeditor.cpp
src/boundarydivision.cpp
src/boundarypropertyeditor.cpp
src/checkmpi.cpp
src/dynamiceditor.cpp
src/edfeditor.cpp
src/egini.cpp
src/generalsetup.cpp
src/glcontrol.cpp
src/glwidget.cpp
src/helpers.cpp
src/main.cpp
src/mainwindow.cpp
src/materiallibrary.cpp
src/maxlimits.cpp
src/meshcontrol.cpp
src/meshingthread.cpp
src/meshtype.cpp
src/meshutils.cpp
src/operation.cpp
src/parallel.cpp
src/projectio.cpp
src/sifgenerator.cpp
src/sifwindow.cpp
src/solverparameters.cpp
src/summaryeditor.cpp
plugins/egconvert.cpp
plugins/egmain.cpp
plugins/egmesh.cpp
plugins/egnative.cpp
plugins/egutils.cpp
plugins/elmergrid_api.cpp
plugins/nglib_api.cpp
plugins/tetlib_api.cpp
twod/renderarea.cpp
twod/twodview.cpp
twod/curveeditor.cpp
src/john.cpp
#------------------------------------------------------------------------------
# Optional input files:
#------------------------------------------------------------------------------
contains(DEFINES, EG_QWT) {
HEADERS += src/convergenceview.h
SOURCES += src/convergenceview.cpp
}
contains(DEFINES, EG_VTK) {
HEADERS += vtkpost/axes.h
vtkpost/featureedge.h
vtkpost/vtkpost.h
vtkpost/isosurface.h
vtkpost/isocontour.h
vtkpost/epmesh.h
vtkpost/colorbar.h
vtkpost/meshpoint.h
vtkpost/meshedge.h
vtkpost/surface.h
vtkpost/preferences.h
vtkpost/vector.h
vtkpost/readepfile.h
vtkpost/streamline.h
vtkpost/timestep.h
vtkpost/ecmaconsole.h
vtkpost/text.h
FORMS += vtkpost/axes.ui
vtkpost/featureedge.ui
vtkpost/isosurface.ui
vtkpost/isocontour.ui
vtkpost/colorbar.ui
vtkpost/surface.ui
vtkpost/meshpoint.ui
vtkpost/meshedge.ui
vtkpost/preferences.ui
vtkpost/vector.ui
vtkpost/readepfile.ui
vtkpost/streamline.ui
vtkpost/timestep.ui
vtkpost/text.ui
SOURCES += vtkpost/axes.cpp
vtkpost/featureedge.cpp
vtkpost/vtkpost.cpp
vtkpost/isosurface.cpp
vtkpost/isocontour.cpp
vtkpost/epmesh.cpp
vtkpost/colorbar.cpp
vtkpost/meshpoint.cpp
vtkpost/meshedge.cpp
vtkpost/surface.cpp
vtkpost/preferences.cpp
vtkpost/vector.cpp
vtkpost/readepfile.cpp
vtkpost/streamline.cpp
vtkpost/timestep.cpp
vtkpost/ecmaconsole.cpp
vtkpost/text.cpp
contains(DEFINES, EG_MATC) {
HEADERS += vtkpost/matc.h
vtkpost/mc.h
FORMS += vtkpost/matc.ui
SOURCES += vtkpost/matc.cpp
}
}
contains(DEFINES, EG_OCC) {
HEADERS += cad/cadview.h
cad/cadpreferences.h
FORMS += cad/cadpreferences.ui
SOURCES += cad/cadview.cpp
cad/cadpreferences.cpp
}
#------------------------------------------------------------------------------
# Resource files:
#------------------------------------------------------------------------------
RESOURCES += ElmerGUI.qrc
win32: RC_FILE += ElmerGUI.rc
macx: RC_FILE = M3Dicon.icns
#------------------------------------------------------------------------------
# END OF FILE
#------------------------------------------------------------------------------
但是,当我编译项目时什么都没有发生,没有出现错误,但我认为应用程序无法调用静态lib。那我该怎么办?
main.cpp 中的 main
应该是:
int main(int argc, char *argv[])
{
return main2(argc, argv);
}
您的行
main2;
确实可以编译,但什么也不做。
相关文章:
- 为不同配置设置MSVC_RUNTIME_LIBRARY的正确方法是什么
- 警告处理为错误这里有什么问题
- 什么时候调用组成单元对象的析构函数
- #定义c-预处理器常量..我做错了什么
- 努力将整数转换为链表。不知道我在这里做错了什么
- C++我的数学有什么问题,为什么我的代码不能正确循环
- 什么时候在C++中返回常量引用是个好主意
- 当在同一名称空间中有两个具有相同签名的函数时,会发生什么
- C++避免重复声明的语法是什么
- c++库的公共头文件中应该包含什么
- 问题:什么是QAbstractItemView::NoEditTriggers的反面
- 有什么方法可以遍历结构吗
- 当类在C++中定义时,有什么方法可以"register"类吗?
- ifstream什么都没读
- 在C++中,将大的无符号浮点数四舍五入为整数的最佳方法是什么
- 实现无开销push_back的最佳方法是什么
- C++从另一个类访问公共静态向量的正确方法是什么
- 从应用程序调用静态库时,QT创建者什么都不会发生
- Qt 创建者,跟踪:不允许操作.什么是永久解决方案
- 我应该在Qt创建者中更改什么,以便使用MinGW而不是microsoft编译器进行编译