2012-05-12 19 views
5

Właśnie zaczynam z C++ i uczę się używać kreatora QT jako IDE, więc podejrzewam, że to może być naprawdę łatwe, ale może czegoś mi brakuje. Zainstalowałem apollo MQ i zainstalowałem Cache apache (C++ messaging service), dzięki czemu mogę wchodzić w interakcje z serwerem w C++. Problem polega na tym, że nie mam pojęcia, co robię :-) (jeszcze) i nie jestem pewien, dlaczego otrzymuję powyższy błąd podczas korzystania z przykładów.Niezdefiniowane symbole dla architektury x86_64 w QT-creator

Jestem prawie pewna, że ​​przykłady są dobre, ponieważ znajdują się w folderze przykładowym źródła, więc to prowadzi mnie do podejrzeń, że konfiguracja projektu nie jest poprawna (jako że jest to jedyna informacja, na którą naprawdę mam wpływ).

Oto plik .pro:

TEMPLATE = app 
CONFIG += console 
CONFIG -= qt 

SOURCES += main.cpp 

INCLUDEPATH += /usr/local/include/activemq-cpp-3.4.2/ 
INCLUDEPATH += /opt/local/lib/ 

Oto zawartość folderu, w którym mam wskazujące (pliki chcę znajdują się w podkatalogach tam):

drwxr-xr-x 13 root admin 442 May 11 19:09 activemq 
drwxr-xr-x 48 root admin 1632 May 11 19:09 cms 
drwxr-xr-x 9 root admin 306 May 11 19:09 decaf 

Oto Błąd pojawia:

20:54:22: Running build steps for project stackexchangeexample... 
20:54:22: Configuration unchanged, skipping qmake step. 
20:54:22: Starting: "/usr/bin/make" -w 
make: Entering directory `/Users/lostsoul/Dropbox/qt_cuda/stackexchangeexample-build-desktop-Desktop_Qt_4_8_1_for_GCC__Qt_SDK__Debug' 
/Users/lostsoul/QtSDK/Desktop/Qt/4.8.1/gcc/bin/qmake -spec ../../../QtSDK/Desktop/Qt/4.8.1/gcc/mkspecs/macx-g++ CONFIG+=declarative_debug -o Makefile ../stackexchangeexample/stackexchangeexample.pro 
make: Leaving directory `/Users/lostsoul/Dropbox/qt_cuda/stackexchangeexample-build-desktop-Desktop_Qt_4_8_1_for_GCC__Qt_SDK__Debug' 
make: Entering directory `/Users/lostsoul/Dropbox/qt_cuda/stackexchangeexample-build-desktop-Desktop_Qt_4_8_1_for_GCC__Qt_SDK__Debug' 
g++ -headerpad_max_install_names -arch x86_64 -Xarch_x86_64 -mmacosx-version-min=10.5 -o stackexchangeexample.app/Contents/MacOS/stackexchangeexample main.o  
Undefined symbols for architecture x86_64: 
    "activemq::library::ActiveMQCPP::initializeLibrary()", referenced from: 
     _main in main.o 
    "activemq::library::ActiveMQCPP::shutdownLibrary()", referenced from: 
     _main in main.o 
    "activemq::core::ActiveMQConnectionFactory::ActiveMQConnectionFactory(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)", referenced from: 
     SimpleProducer::run()  in main.o 
    "cms::CMSException::CMSException(cms::CMSException const&)", referenced from: 
     SimpleProducer::run()  in main.o 
    "typeinfo for cms::CMSException", referenced from: 
     GCC_except_table15 in main.o 
     GCC_except_table16 in main.o 
     SimpleProducer::run()  in main.o 
    "cms::CMSException::~CMSException()", referenced from: 
     SimpleProducer::run()  in main.o 
    "decaf::lang::Thread::getId()", referenced from: 
     SimpleProducer::run()  in main.o 
    "decaf::lang::Long::toString(long long)", referenced from: 
     SimpleProducer::run()  in main.o 
ld: symbol(s) not found for architecture x86_64 
collect2: ld returned 1 exit status 
make: *** [stackexchangeexample.app/Contents/MacOS/stackexchangeexample] Error 1 
make: Leaving directory `/Users/lostsoul/Dropbox/qt_cuda/stackexchangeexample-build-desktop-Desktop_Qt_4_8_1_for_GCC__Qt_SDK__Debug' 
20:54:22: The process "/usr/bin/make" exited with code 2. 
Error while building project stackexchangeexample (target: Desktop) 
When executing build step 'Make' 

i czy to pomaga, oto kod biegnę (nie może być przydatny do nikogo o pomoc ing bo trzeba zainstalować kilka rzeczy, aby to działało, ale na wszelki wypadek to pomaga):

/* 
* Licensed to the Apache Software Foundation (ASF) under one or more 
* contributor license agreements. See the NOTICE file distributed with 
* this work for additional information regarding copyright ownership. 
* The ASF licenses this file to You under the Apache License, Version 2.0 
* (the "License"); you may not use this file except in compliance with 
* the License. You may obtain a copy of the License at 
* 
*  http://www.apache.org/licenses/LICENSE-2.0 
* 
* Unless required by applicable law or agreed to in writing, software 
* distributed under the License is distributed on an "AS IS" BASIS, 
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
* See the License for the specific language governing permissions and 
* limitations under the License. 
*/ 

#include <decaf/lang/Thread.h> 
#include <decaf/lang/Runnable.h> 
#include <decaf/util/concurrent/CountDownLatch.h> 
#include <decaf/lang/Long.h> 
#include <decaf/util/Date.h> 
#include <activemq/core/ActiveMQConnectionFactory.h> 
#include <activemq/util/Config.h> 
#include <activemq/library/ActiveMQCPP.h> 
#include <cms/Connection.h> 
#include <cms/Session.h> 
#include <cms/TextMessage.h> 
#include <cms/BytesMessage.h> 
#include <cms/MapMessage.h> 
#include <cms/ExceptionListener.h> 
#include <cms/MessageListener.h> 
#include <stdlib.h> 
#include <stdio.h> 
#include <iostream> 
#include <memory> 

using namespace activemq; 
using namespace activemq::core; 
using namespace decaf; 
using namespace decaf::lang; 
using namespace decaf::util; 
using namespace decaf::util::concurrent; 
using namespace cms; 
using namespace std; 

//////////////////////////////////////////////////////////////////////////////// 
class SimpleProducer : public Runnable { 
private: 

    Connection* connection; 
    Session* session; 
    Destination* destination; 
    MessageProducer* producer; 
    bool useTopic; 
    bool clientAck; 
    unsigned int numMessages; 
    std::string brokerURI; 
    std::string destURI; 

private: 

    SimpleProducer(const SimpleProducer&); 
    SimpleProducer& operator= (const SimpleProducer&); 

public: 

    SimpleProducer(const std::string& brokerURI, unsigned int numMessages, 
        const std::string& destURI, bool useTopic = false, bool clientAck = false) : 
     connection(NULL), 
     session(NULL), 
     destination(NULL), 
     producer(NULL), 
     useTopic(useTopic), 
     clientAck(clientAck), 
     numMessages(numMessages), 
     brokerURI(brokerURI), 
     destURI(destURI) { 
    } 

    virtual ~SimpleProducer(){ 
     cleanup(); 
    } 

    void close() { 
     this->cleanup(); 
    } 

    virtual void run() { 
     try { 

      // Create a ConnectionFactory 
      auto_ptr<ActiveMQConnectionFactory> connectionFactory(
       new ActiveMQConnectionFactory(brokerURI)); 

      // Create a Connection 
      try{ 
       connection = connectionFactory->createConnection(); 
       connection->start(); 
      } catch(CMSException& e) { 
       e.printStackTrace(); 
       throw e; 
      } 

      // Create a Session 
      if(clientAck) { 
       session = connection->createSession(Session::CLIENT_ACKNOWLEDGE); 
      } else { 
       session = connection->createSession(Session::AUTO_ACKNOWLEDGE); 
      } 

      // Create the destination (Topic or Queue) 
      if(useTopic) { 
       destination = session->createTopic(destURI); 
      } else { 
       destination = session->createQueue(destURI); 
      } 

      // Create a MessageProducer from the Session to the Topic or Queue 
      producer = session->createProducer(destination); 
      producer->setDeliveryMode(DeliveryMode::NON_PERSISTENT); 

      // Create the Thread Id String 
      string threadIdStr = Long::toString(Thread::getId()); 

      // Create a messages 
      string text = (string)"Hello world! from thread " + threadIdStr; 

      for(unsigned int ix=0; ix<numMessages; ++ix){ 
       TextMessage* message = session->createTextMessage(text); 

       message->setIntProperty("Integer", ix); 

       // Tell the producer to send the message 
       printf("Sent message #%d from thread %s\n", ix+1, threadIdStr.c_str()); 
       producer->send(message); 

       delete message; 
      } 

     }catch (CMSException& e) { 
      e.printStackTrace(); 
     } 
    } 

private: 

    void cleanup(){ 

     // Destroy resources. 
     try{ 
      if(destination != NULL) delete destination; 
     }catch (CMSException& e) { e.printStackTrace(); } 
     destination = NULL; 

     try{ 
      if(producer != NULL) delete producer; 
     }catch (CMSException& e) { e.printStackTrace(); } 
     producer = NULL; 

     // Close open resources. 
     try{ 
      if(session != NULL) session->close(); 
      if(connection != NULL) connection->close(); 
     }catch (CMSException& e) { e.printStackTrace(); } 

     try{ 
      if(session != NULL) delete session; 
     }catch (CMSException& e) { e.printStackTrace(); } 
     session = NULL; 

     try{ 
      if(connection != NULL) delete connection; 
     }catch (CMSException& e) { e.printStackTrace(); } 
     connection = NULL; 
    } 
}; 

//////////////////////////////////////////////////////////////////////////////// 
int main(int argc AMQCPP_UNUSED, char* argv[] AMQCPP_UNUSED) { 

    activemq::library::ActiveMQCPP::initializeLibrary(); 

    std::cout << "=====================================================\n"; 
    std::cout << "Starting the example:" << std::endl; 
    std::cout << "-----------------------------------------------------\n"; 

    // Set the URI to point to the IPAddress of your broker. 
    // add any optional params to the url to enable things like 
    // tightMarshalling or tcp logging etc. See the CMS web site for 
    // a full list of configuration options. 
    // 
    // http://activemq.apache.org/cms/ 
    // 
    // Wire Format Options: 
    // ===================== 
    // Use either stomp or openwire, the default ports are different for each 
    // 
    // Examples: 
    // tcp://127.0.0.1:61616      default to openwire 
    // tcp://127.0.0.1:61616?wireFormat=openwire same as above 
    // tcp://127.0.0.1:61613?wireFormat=stomp  use stomp instead 
    // 
    std::string brokerURI = 
     "failover://(tcp://127.0.0.1:61616" 
//  "?wireFormat=openwire" 
//  "&connection.useAsyncSend=true" 
//  "&transport.commandTracingEnabled=true" 
//  "&transport.tcpTracingEnabled=true" 
//  "&wireFormat.tightEncodingEnabled=true" 
     ")"; 

    //============================================================ 
    // Total number of messages for this producer to send. 
    //============================================================ 
    unsigned int numMessages = 2000; 

    //============================================================ 
    // This is the Destination Name and URI options. Use this to 
    // customize where the Producer produces, to have the producer 
    // use a topic or queue set the 'useTopics' flag. 
    //============================================================ 
    std::string destURI = "TEST.FOO"; 

    //============================================================ 
    // set to true to use topics instead of queues 
    // Note in the code above that this causes createTopic or 
    // createQueue to be used in the producer. 
    //============================================================ 
    bool useTopics = false; 

    // Create the producer and run it. 
    SimpleProducer producer(brokerURI, numMessages, destURI, useTopics); 

    // Publish the given number of Messages 
    producer.run(); 

    // Before exiting we ensure that all CMS resources are closed. 
    producer.close(); 

    std::cout << "-----------------------------------------------------\n"; 
    std::cout << "Finished with the example." << std::endl; 
    std::cout << "=====================================================\n"; 

    activemq::library::ActiveMQCPP::shutdownLibrary(); 
} 

Właśnie stworzyliśmy pusty C++ projektu, zmodyfikowany plik .pro zawierać ścieżkę do bibliotek a następnie skopiuj/wklej kod do main.cpp. Jakiś pomysł, co to powoduje? i jak mogę temu zapobiec?

Odpowiedz

4

Wygląda na to, że zapomniałeś ścieżek biblioteki ; definiujesz INCLUDEPATH z nowymi wartościami, ale nie dodajesz odpowiadającej LIBPATH lub LIBRARYPATH lub innej nazwy równoważnej zmiennej dla bibliotek. Czy nie potrzebujesz również odpowiednich parametrów dla określonych bibliotek?

+0

Przykro mi, jestem naprawdę nowy w C++ i nowszym w QT, jeśli mam zamiar dołączyć 20 lub więcej bibliotek, które mam w powyższym kodzie, jest jakiś sposób, aby to zrobić bez ich indywidualnego deklarowania? Widziałem tę opcję, o której wspomniałeś, kiedy otrzymywałem 'file not found' dla bibliotek, które zawierałem, więc próbowałem uzyskać folder nadrzędny, więc dostałem je wszystkie. Nie jestem pewien, czy rozumiem w pełni, ale czy powinienem wyraźnie wspomnieć o tych, których zamierzam użyć? Przepraszam, jeśli całkowicie błędnie zinterpretowałem twoją odpowiedź. – Lostsoul

+0

Nadal walczę z tym. Nie mogę go złamać, ponieważ nie jestem pewien, jakiego pliku szuka, w folderach, które wskażę, są tylko pliki * .h, ale kiedy kliknę prawym przyciskiem myszy plik pro i wybiorę biblioteki, wydaje się, że chce plik – Lostsoul

+1

Mam to !! Kliknąłem plik pro i dodałem do biblioteki, poszedłem do biblioteki systemowej i zamiast dodać ścieżkę do rzeczywistych plików .h wskazałem na plik w/usr/local/lib. To spowodowało, że twórca qt dodał to do mojego pliku .pro i wydaje się teraz budować: unix | win32: LIBS + = -lactivemq-cpp – Lostsoul

Powiązane problemy