简体   繁体   English

如何将用C编写的源代码从另一个项目包含到我自己的Visual Studio C ++项目中

[英]How can I include source code written in C from another project into my own project in C++ in Visual Studio

I want to use Potrace for a C++ project on Windows in Visual Studio, but I have no clue of how to include Potrace into my project. 我想在Visual Studio中使用Potrace在Windows上进行C ++项目,但我不知道如何将Potrace包含到我的项目中。 I have tried to compile the C files using Cygwin, and that way create an .a file and then link to it in visual studio, but that didn't work. 我试图使用Cygwin编译C文件,这样创建一个.a文件,然后在visual studio中链接到它,但这不起作用。 Visual Studio were able to recognize the the functions from Potrace, but when running a test program with Potrace(Calling potrace_version() ), Visual Studio got the error “LNK2019 unresolved external symbol _potrace_version referenced in function_main” Visual Studio能够识别Potrace中的函数,但是当使用Potrace运行测试程序(调用potrace_version())时,Visual Studio得到错误“LNK2019未解析的外部符号_potrace_version在function_main中引用”

I have gotten it to work on Ubuntu by using the technique mentioned above, and then compiling my code with: g++ main.cpp backenddxf.cpp ImageManipulation.cpp ./libubuntu/libpotrace.a -o test.out 'pkg-config --cflags --libs opencv 我已经通过使用上面提到的技术在Ubuntu上工作,然后用以下代码编译我的代码:g ++ main.cpp backenddxf.cpp ImageManipulation.cpp ./libubuntu/libpotrace.a -o test.out'pkg-config - cflags --libs opencv

Do I have to compile the source code(Called “source distribution” on the website) to a lib file, and then link it to my project, in that case, how do I do so? 我是否必须将源代码(在网站上称为“源代码分发”)编译为lib文件,然后将其链接到我的项目,在这种情况下,我该怎么做? Or is there something I have missed. 或者有什么我错过了。 I am using Visual Studio 2017 on Windows 10. 我在Windows 10上使用Visual Studio 2017。

I am not to proficient in the workings of C++ so a detailed explanation is greatly appreciated. 我不是要精通C ++的工作原理,所以非常感谢详细的解释。

I got it working using this answer by Yaakov to compile potrace to an .a file 我使用Yaakov的这个答案将jarrace编译成.a文件

./configure --prefix=/usr/x86_64-64-ming32/sys-root/mingw --host=x86_64-w64-mingw32 --with-libpotrace

and then 然后

make

Afterwards I used this answer by Stuti Rastogi on how to link the .a file in Visual Studio. 之后我使用Stuti Rastogi的这个答案来解决如何在Visual Studio中链接.a文件的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM