I encountered "winnt.h No target architecture" error though I included windows.h up to first.

xuanbao · · 503 次点击    
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
<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&#34;E:/WindowsSDK/Include/10.0.15063.0/um&#34; -I&#34;E:/WindowsSDK/Include/10.0.15063.0/shared&#34; // // #include &lt;windows.h&gt; // // void test() { // // } import &#34;C&#34; </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 &#34;No Target Architecture&#34; #error &#34;No Target Architecture&#34; ^~~~~ </code></pre> <p>Most of answers I found were &#34;put #include &lt;windows.h&gt; up to first&#34;. How can I get rid of this error?</p> <hr/>**评论:**<br/><br/>JHunz: <pre><p>Pretty sure your formatting is wrong. I can&#39;t comment on the format of the build tags themselves because I don&#39;t use them like that, but I&#39;m fairly certain there needs to be a newline after them for them to be treated as such. </p> <p>Also, I&#39;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&#34;E:/WindowsSDK/Include/10.0.15063.0/um&#34; -I&#34;E:/WindowsSDK/Include/10.0.15063.0/shared&#34; package whatever // #include &lt;windows.h&gt; // // void test() { // // } import &#34;C&#34; </code></pre></pre>rlj1202: <pre><p>When I included another header,</p> <pre><code>#include &lt;windows.h&gt; #include &lt;PortableDevice.h&gt; </code></pre> <p>It can&#39;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 &lt;PortableDevice.h&gt; ^~~~~~~~~~~~~~~~~~ </code></pre></pre>

入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889

503 次点击  
加入收藏 微博
0 回复
暂无回复
添加一条新回复 (您需要 登录 后才能回复 没有账号 ?)
  • 请尽量让自己的回复能够对别人有帮助
  • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`
  • 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
  • 图片支持拖拽、截图粘贴等方式上传