看板 C_and_CPP 關於我們 聯絡資訊
開發平台(Platform): (Ex: Win10, Linux, ...) MacOS Mojave 10.14.6 編譯器(Ex: GCC, clang, VC++...)+目標環境(跟開發平台不同的話需列出) Xcode Version 10.3 額外使用到的函數庫(Library Used): (Ex: OpenGL, ...) matplotlib-cpp https://github.com/lava/matplotlib-cpp 問題(Question): 長話短說:想要在C++上畫簡單的 y=f(x) 圖,例如 y=3x^2 之類的。 所以想說用這個函數庫,看起來是從Python來的,而我先前就經常用 Python。但沒想到一直遇到問題。首先是找不到Python.h,後來在前面 加上 Python/ 就解決了。但後來就變成找不到 numpy/arrayobject.h, 即便我確實有在 Finder 中找到這個檔案,也試著在 Search_Header_Path 加入該路徑,但還是沒有效果.. 細節: 執行其Github上最簡單的第一個範例時,就出現了錯誤 https://github.com/lava/matplotlib-cpp #include "matplotlibcpp.h" namespace plt = matplotlibcpp; int main() { plt::plot({1,3,2,4}); plt::show(); } 錯誤訊息都發生在執行 matplotlibcpp.h 的時候。 最初的錯誤是:'Python.h' file not found 這時的指令為 #include <Python.h> 但在我將 include 的內容改為 #include <Python/Python.h> 之後就ok了。 (參考自https://reurl.cc/YLAno) 可是就發生了第二個錯誤訊息:'numpy/arrayobject.h' file not found 在作者Github上也有網友提出相同問題,作者是說只要你設定好正確檔案路徑 就可以了(https://github.com/lava/matplotlib-cpp/issues/46)。 後來我試著在 terminal 中進入 Python,然後 >>> import numpy as np >>> np.get_include() '/Users/Ethan/Library/Python/3.6/lib/python /site-packages/numpy/core/include' 於是我將上述路徑新增到 Xcode >> Project >> build settings >> target >> Search Header Path 不論是底下的 debug,還是 release,我將上述路徑去掉前後單引號後直接貼上。 結果不但沒解決問題,反而還使我找不到 Python.h,設定仍為 #include<Python/Python.h> 'Python.h' file not found 很神奇的是,如果我將上述路徑的 /include 去掉,那就找得到 Python.h 也就是說,Python.h 看起來好像是位於 .../numpy/core 資料夾中,但我 從 Finder 去看,卻找不到 Python.h,所以我也搞不懂為什麼去掉 /include 之後就沒有出現 'Python.h' file not found 錯誤訊息。 話說回來,就算去掉了/include,還是會出現錯誤訊息: 'numpy/arrayobject.h' file not found 但是我可以肯定/include之中確實有 /numpy/arrayobject.h 這個檔案, 因為我有直接在 Finder 看見它。 總之這真的是太奇怪了,抱歉我第一次使用,可能問到蠢問題 QQ 我有Google滿多資料,包括有人提到將上述 np.get_include() 得到的路徑 直接放入 Cflags 環境變數中(https://github.com/hmmlearn/hmmlearn/issues/43)。 我有照著做,在 terminal 輸入底下這行 export CFLAGS="-I /Users/Ethan/Library/Python/3.6/lib/python/ site-packages/numpy/core/include $CFLAGS" 然後在 terminal 輸入 env 檢查是否設定好環境變數,也是有。 目前真的不知道該怎麼做才好了 QQ 還請各位大神幫幫我 感謝大大 <(__)> 我只是想要用 c++ 畫圖 QQ -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 123.192.0.245 (臺灣) ※ 文章網址: https://www.ptt.cc/bbs/C_and_CPP/M.1565624990.A.3F3.html ※ 編輯: Philethan (123.192.0.245 臺灣), 08/12/2019 23:56:26