2014-03-25 65 views
0

我正在使用SFML創建一個項目。到目前爲止,一切正常。我創建了一個名爲BufferHelper.cpp的類,然後出現錯誤。鏈接SFML時發生錯誤。 LNK2001

我一起工作: 的Visual Studio專業2013 SFML 2.1 的Windows 8.1

我添加了所有libaries

的 'SFML-lib.dll對發行 和' SFML-LIB-d .dll文件對調試

錯誤日誌:

Error 1 error LNK2001: unresolved external symbol "public: class sf::SoundBuffer __thiscall BufferHelper::MergeBuffers(class sf::SoundBuffer,class sf::SoundBuffer)" ([email protected]@@[email protected]@@[email protected]@Z) C:\Users\Krisjanis\documents\visual studio 2013\Projects\BD_Test\BD_Test\main.obj BD_Test 
Error 2 error LNK1120: 1 unresolved externals C:\Users\Krisjanis\documents\visual studio 2013\Projects\BD_Test\Release\BD_Test.exe BD_Test 

Main.cpp的

#include <SFML/Graphics.hpp> 
#include <SFML/Audio.hpp> 
#include <iostream> 
#include "BufferHelper.h" 

int main() 
{ 
    sf::SoundBufferRecorder recorder; 
    sf::SoundBufferRecorder recorder2; 

    sf::SoundBuffer buffer; 
    sf::SoundBuffer buffer2; 

    sf::Sound sound; 
    sf::Sound sound2; 

    int iTrackActive = 1; 

    bool bTrack1Active = true; 
    bool bTrack2Active = false; 

    sf::RenderWindow window(sf::VideoMode(1200, 800), "Loopify!"); 
    //sf::RenderWindow window(sf::VideoMode(1200, 800), "Loopify!", sf::Style::Fullscreen); 
    sf::Texture texture; 
    texture.loadFromFile("images/a.png"); 

    BufferHelper a; 
    sf::SoundBuffer finalbuffer = a.MergeBuffers(buffer, buffer2); 

    sf::Sprite sprite; 
    sprite.setTexture(texture); 

    bool recording = false; 
    if (!sf::SoundBufferRecorder::isAvailable()) 
    { 
     std::cout << "Recorder not available"; 
    } 
    else 
    { 
     std::cout << "GO AHEAD AND RECORD"; 
    } 

    while (window.isOpen()) 
    { 
     sf::Event event; 
     while (window.pollEvent(event)) 
     { 
      if (event.type == sf::Event::Closed) 
       window.close(); 
      if (event.type == sf::Event::KeyPressed) 
      { 
       if (event.key.code == sf::Keyboard::Space && !recording) 
       { 
        recording = true; 
        recorder.start(); 

       } 
       else if (event.key.code == sf::Keyboard::Space && recording) 
       { 
        recorder.stop(); 
        recording = false; 
        if (iTrackActive == 1) 
        { 
         buffer = recorder.getBuffer(); 
         sound.setBuffer(buffer); 
         sound.setLoop(true); 
         sound.play(); 
        } 
        if (iTrackActive == 2) 
        { 
         buffer2 = recorder.getBuffer(); 
         sound2.setBuffer(buffer); 
         sound2.setLoop(true); 
         sound2.play(); 
        } 
       } 
       else if (event.key.code == sf::Keyboard::Num1) 
       { 
        iTrackActive = 1; 
       } 
       else if (event.key.code == sf::Keyboard::Num2) 
       { 
        iTrackActive = 2; 
       } 
      } 
     } 
     window.clear(); 
     window.draw(sprite); 
     window.display(); 
    } 

    return 0; 
} 

BufferHelper.cpp

#include <SFML/System.hpp> 
#include <SFML/Audio.hpp> 
#include "BufferHelper.h" 
#include <iostream> 
#include <vector> 


BufferHelper::BufferHelper() 
{ 

} 

sf::SoundBuffer MergeBuffers(sf::SoundBuffer BufferOne, sf::SoundBuffer BufferTwo) 
{ 

    int iLength; 
    int iShortLength; 
    const sf::Int16* LongerSamples; 
    const sf::Int16* ShorterSamples; 

    if (BufferOne.getSampleCount() > BufferTwo.getSampleCount()) 
    { 
     LongerSamples = BufferOne.getSamples(); 
     ShorterSamples = BufferTwo.getSamples(); 
     iLength = BufferOne.getSampleCount(); 
     iShortLength = BufferTwo.getSampleCount(); 
    } 
    else 
    { 

     LongerSamples = BufferTwo.getSamples(); 
     ShorterSamples = BufferOne.getSamples(); 
     iLength = BufferTwo.getSampleCount(); 
     iShortLength = BufferOne.getSampleCount(); 
    } 

    std::vector<sf::Int16> FinalSamplesVector; 
    FinalSamplesVector.reserve(iLength); 

    for (int i = 0; i < iLength; i++) 
    { 
     if (i < iShortLength) 
     { 
      double dSampleOne = (LongerSamples[i] + 32768.)/65535.; 
      double dSampleTwo = (ShorterSamples[i] + 32768.)/65535.; 
      double dResult = 0; 

      if (dSampleOne < 0.5 && dSampleTwo < 0.5) 
      { 
       dResult = 2 * dSampleOne * dSampleTwo; 
      } 
      else 
      { 
       dResult = 2 * (dSampleOne + dSampleTwo) - 2 * dSampleOne * dSampleTwo - 1; 
      } 

      FinalSamplesVector.push_back(static_cast<sf::Int16>(dResult * 65535. - 32768.)); 
     } 
     else 
     { 
      FinalSamplesVector.push_back(LongerSamples[i]); 
     } 
    } 

    sf::SoundBuffer FinalBuffer; 
    FinalBuffer.loadFromSamples(&FinalSamplesVector[0], FinalSamplesVector.size(), 2, 44100); 

    return FinalBuffer; 
} 

BufferHelper::~BufferHelper() 
{ 
} 

BufferHelper.h

#pragma once 
#include <SFML/Graphics.hpp> 
#include <SFML/Audio.hpp> 
using namespace sf; 
class BufferHelper 
{ 
public: 
    BufferHelper(); 

    sf::SoundBuffer MergeBuffers(sf::SoundBuffer, sf::SoundBuffer); 

    ~BufferHelper(); 
}; 

我會感激收到任何形式的反饋。

回答

1

您沒有聲明函數MergeBuffers()的主體。 這有什麼好做SFML,只是在你的CPP文件中添加

sf::SoundBuffer BufferHelper::MergeBuffers(sf::SoundBuffer, sf::SoundBuffer) 
{ 
// some code 
} 

編輯:我知道你錯誤地重新複製了你的main.cpp文件代碼。請顯示BufferHelper.cpp的好代碼

+0

感謝你的理解,你是對的,我錯誤地複製了錯誤的代碼。 但是你的一小段代碼告訴我正確的做事方式...... – krishkule