Qt Creator从应用程序调用静态库时没有任何反应

时间:2017-12-09 16:25:44

标签: c++ qt qt-creator

Qt Creator从应用程序调用静态库时没有任何反应。 我有这些代码行作为我的main.cpp主应用程序文件:

mov

那是.Pro文件:

#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;

}

和我的main2.cpp静态库文件如下:

#-------------------------------------------------
#
# 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

并且是.pro文件:

/*****************************************************************************
 *                                                                           *
 *  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,'/'))='\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;

}

但是当我编译项目时没有任何反应,没有出现错误,但我认为app无法调用静态lib.so我该怎么办?

1 个答案:

答案 0 :(得分:1)

main.cpp 中的main应为:

int main(int argc, char *argv[])
{
  return main2(argc, argv);
}

你的行

main2;

编译好,但什么都不做。

相关问题