<p>Recently i get obsessed with developing program with cgo. My first purpose is to make program to communicate with MTP device on windows such as Android Device.</p>
<p>I tried to just include some essential header files and build. Here are what I got.</p>
<p><strong>codes:</strong></p>
<pre><code>// #cgo windows CFLAGS: -I"E:/WindowsSDK/Include/10.0.15063.0/um" -I"E:/WindowsSDK/Include/10.0.15063.0/shared"
//
// #include <windows.h>
//
// void test() {
//
// }
import "C"
</code></pre>
<p><strong>outputs:</strong></p>
<pre><code>In file included from E:/WindowsSDK/Include/10.0.15063.0/shared/minwindef.h:182:0,
from E:/WindowsSDK/Include/10.0.15063.0/shared/windef.h:24,
from E:/WindowsSDK/Include/10.0.15063.0/um/windows.h:168,
from .\main.go:5:
E:/WindowsSDK/Include/10.0.15063.0/um/winnt.h:154:2: error: #error "No Target Architecture"
#error "No Target Architecture"
^~~~~
</code></pre>
<p>Most of answers I found were "put #include <windows.h> up to first".
How can I get rid of this error?</p>
<hr/>**评论:**<br/><br/>JHunz: <pre><p>Pretty sure your formatting is wrong. I can't comment on the format of the build tags themselves because I don't use them like that, but I'm fairly certain there needs to be a newline after them for them to be treated as such. </p>
<p>Also, I'm fairly certain you need to have your package declaration in the file between the build tags and the C code you intend to import. </p>
<p>I think it should look more like this: </p>
<pre><code>// #cgo windows CFLAGS: -I"E:/WindowsSDK/Include/10.0.15063.0/um" -I"E:/WindowsSDK/Include/10.0.15063.0/shared"
package whatever
// #include <windows.h>
//
// void test() {
//
// }
import "C"
</code></pre></pre>rlj1202: <pre><p>When I included another header,</p>
<pre><code>#include <windows.h>
#include <PortableDevice.h>
</code></pre>
<p>It can't find PortableDevice.h, which is actually in E:/WindowsSDK/Include/10.0.15063.0/um.</p>
<pre><code>.\main.go:8:10: fatal error: PortableDevice.h: No such file or directory
#include <PortableDevice.h>
^~~~~~~~~~~~~~~~~~
</code></pre></pre>
I encountered "winnt.h No target architecture" error though I included windows.h up to first.
xuanbao · · 503 次点击这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889
0 回复
- 请尽量让自己的回复能够对别人有帮助
- 支持 Markdown 格式, **粗体**、~~删除线~~、
`单行代码`
- 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
- 图片支持拖拽、截图粘贴等方式上传