[問題] 無法將Class拆成.h跟.cpp

看板C_and_CPP作者 (十八尖山內馬爾)時間6年前 (2018/07/19 23:31), 編輯推噓2(2010)
留言12則, 6人參與, 6年前最新討論串1/1
大家好 小弟有一個範例程式一直跑不起來 希望大家能協助 我做的事很簡單 就像下面描述的一樣簡單: VS2010 新增一個名為 TEST 的 Win32 Console Application 專案 然後在這個專案裡面額外新增一個名為 CWin 的 Class Libraty 計畫 編譯器沒有做其他任何額外的設定 貼上所有程式碼: // CWin.h #pragma once class CWin { public: void nothing(); }; // CWin.cpp #include "stdafx.h" #include "CWin.h" void CWin::nothing() { }; // TEST.cpp #include "stdafx.h" #include "../CWin/CWin.h" int main() { CWin win1; win1.nothing(); return 0; } 出現錯誤訊息是: Error 1 error LNK2019: unresolved external symbol "public: void __thiscall CWin::nothing(void)" (?nothing@CWin@@QAEXXZ) referenced in function _main c:\...\TEST.obj Error 2 error LNK1120: 1 unresolved externals c:\...\TEST.exe 1 -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 180.217.171.213 ※ 文章網址: https://www.ptt.cc/bbs/C_and_CPP/M.1532014284.A.89D.html

07/19 23:35, 6年前 , 1F
linker沒設好 僅此而已
07/19 23:35, 1F

07/19 23:37, 6年前 , 2F
想請問怎麼設? 謝謝
07/19 23:37, 2F

07/19 23:48, 6年前 , 3F
看起來是連結的時候找不到你的CWin實體
07/19 23:48, 3F

07/20 02:38, 6年前 , 4F
大括號後面接分號?
07/20 02:38, 4F

07/20 08:52, 6年前 , 5F
專案上按右鍵>Properties>Linker>Input>把lib加在
07/20 08:52, 5F

07/20 08:52, 6年前 , 6F
Additional Dependencies裡面
07/20 08:52, 6F

07/20 09:25, 6年前 , 7F
我的類別是DLL 就算改成lib然後照p大方式還是失敗
07/20 09:25, 7F

07/20 11:04, 6年前 , 8F

07/20 12:47, 6年前 , 9F
你build dll之後同一個目錄內會有lib,要把那個lib加進
07/20 12:47, 9F

07/20 12:48, 6年前 , 10F
dependency,但是還要注意lib路徑問題,也許可以用
07/20 12:48, 10F

07/20 12:51, 6年前 , 11F
$(SolutionDir)Cwin/release/cwin.lib這樣的方式填入
07/20 12:51, 11F

07/20 12:51, 6年前 , 12F
不過還是要看你的檔案是產生在哪
07/20 12:51, 12F
文章代碼(AID): #1RKAxCYT (C_and_CPP)