<p>I would like to include C source files together with my bindings for raylib <a href="https://github.com/gen2brain/raylib-go">https://github.com/gen2brain/raylib-go</a>.
It is not a library that you can just apt-get/dnf/brew so I think it would be nice if I bundle C source together with Go files.</p>
<p>I know for some examples, like gousb or glwf3 that bundle C source files, and include .c files together with .h but I am not sure where to start.
So in raylib C version, there are 5-6 .c files, they are built to .o and then linked to one static library. How will that work in cgo, if I just include .c files how are they linked?</p>
<hr/>**评论:**<br/><br/>rsc: <pre><p>Put the C files in your package's directory and Go will take care of compiling them to .o, saving the .o in the compiled Go package, and passing them to the final link. </p></pre>umpahblah: <pre><p>Thanks, I will try. Say I want to move C version to internal/ dir, can I just add that dir to include path -I and include .c files. Will that be the same, it will still compile them?</p></pre>rsc: <pre><p>The C files need to be in the same dir as the Go cgo wrapper.</p></pre>umpahblah: <pre><p>Thanks a lot, it works! It does look a little messy, but more convenient.</p></pre>justinisrael: <pre><p>Another approach is to put the C files in whatever subdirectory you want but then have a single c/cpp file next to your go source that just includes the other source. </p></pre>justinisrael: <pre><p>Pigosat does this, by compiling in the picosat source
<a href="https://github.com/wkschwartz/pigosat" rel="nofollow">https://github.com/wkschwartz/pigosat</a></p></pre>
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889
- 请尽量让自己的回复能够对别人有帮助
- 支持 Markdown 格式, **粗体**、~~删除线~~、
`单行代码`
- 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
- 图片支持拖拽、截图粘贴等方式上传