Reputation:
Qt Creator Nothing happen when call a static library from an application. I have these line of codes as my main.cpp main app file:
#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;
}
and that's .Pro file:
#-------------------------------------------------
#
# 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
and my main2.cpp static library file is as below:
/*****************************************************************************
* *
* 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: [email protected] *
* 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,'/'))='\0';
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 = %s\nDYLD_LIBRARY_PATH=%s\nELMER_HOME=%s\n",
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;
}
and it's .pro file:
#==============================================================================
#
# 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
#------------------------------------------------------------------------------
but nothing happen when I compile the project, No error appears but I think app could not call static lib.so what should I do?
Upvotes: 1
Views: 152
Reputation: 10079
Your main
in main.cpp should be:
int main(int argc, char *argv[])
{
return main2(argc, argv);
}
your line
main2;
do compiles fine, but does nothing.
Upvotes: 1