- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在学习 Cython 并尝试运行一个在这里找到的简单示例:making C library callable .
我使用 VS 2019 创建 mylib.lib
和 setup.py
构建 Cython 扩展(有关详细信息和代码,请参见下文),但是链接器失败并显示错误:
error LNK2001: unresolved external symbol hello
nm mylib.lib
我在其他帖子中发现我可以看到符号
_hello
存在:
D:\Codes\git_folders\my_repository\Cython_test\lib>nm mylib.lib
...
Debug/examples.obj:
...
00000000 T _hello
...
出了什么问题?
pyexamples.pyx
cdef extern from "examples.h":
void hello(const char *name)
def py_hello(name: bytes) -> None:
hello(name)
setup.py
from distutils.core import setup
from distutils.extension import Extension
from Cython.Build import cythonize
examples_extension = Extension(
name="pyexamples",
sources=["pyexamples.pyx"],
libraries=["mylib"],
library_dirs=["lib"],
include_dirs=["lib"]
)
setup(
name="pyexamples",
ext_modules=cythonize([examples_extension])
)
examples.c
#include <stdio.h>
#include "examples.h"
void hello(const char *name) {
printf("hello %s\n", name);
}
examples.h
#ifndef EXAMPLES_H
#define EXAMPLES_H
void hello(const char *name);
#endif
但是,如果我运行此命令,
python setup.py build_ext --inplace
我收到了这个错误。
running build_ext
building 'pyexamples' extension
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.27.29110\bin\HostX86\x64\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD -Ilib -IC:\Users\swsyo\anaconda3\include -IC:\Users\swsyo\anaconda3\include "-IC:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.27.29110\ATLMFC\include" "-IC:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.27.29110\include" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\ucrt" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\shared" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\um" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\winrt" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\cppwinrt" /Tcpyexamples.c /Fobuild\temp.win-amd64-3.7\Release\pyexamples.obj
pyexamples.c
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.27.29110\bin\HostX86\x64\link.exe /nologo /INCREMENTAL:NO /LTCG /DLL /MANIFEST:EMBED,ID=2 /MANIFESTUAC:NO /LIBPATH:lib /LIBPATH:C:\Users\swsyo\anaconda3\libs /LIBPATH:C:\Users\swsyo\anaconda3\PCbuild\amd64 "/LIBPATH:C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.27.29110\ATLMFC\lib\x64" "/LIBPATH:C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.27.29110\lib\x64" "/LIBPATH:C:\Program Files (x86)\Windows Kits\10\lib\10.0.18362.0\ucrt\x64" "/LIBPATH:C:\Program Files (x86)\Windows Kits\10\lib\10.0.18362.0\um\x64" mylib.lib /EXPORT:PyInit_pyexamples build\temp.win-amd64-3.7\Release\pyexamples.obj /OUT:D:\git_folders\my_repository\Cython_test\pyexamples.cp37-win_amd64.pyd /IMPLIB:build\temp.win-amd64-3.7\Release\pyexamples.cp37-win_amd64.lib
Creating library build\temp.win-amd64-3.7\Release\pyexamples.cp37-win_amd64.lib and object build\temp.win-amd64-3.7\Release\pyexamples.cp37-win_amd64.exp
pyexamples.obj : error LNK2001: unresolved external symbol hello
D:\git_folders\my_repository\Cython_test\pyexamples.cp37-win_amd64.pyd : fatal error LNK1120: 1 unresolved externals
error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Community\\VC\\Tools\\MSVC\\14.27.29110\\bin\\HostX86\\x64\\link.exe' failed with exit status 1120
更多详情:
dumpbin mylib.lib
命令查看是否
hello
函数在库中。这是正确的方法吗?我没有看到名字
hello
在这个总结中。
D:\Codes\git_folders\my_repository\Cython_test\lib>dumpbin mylib.lib
Microsoft (R) COFF/PE Dumper Version 14.27.29111.0
Copyright (C) Microsoft Corporation. All rights reserved.
Dump of file mylib.lib
File Type: LIBRARY
Summary
E8 .chks64
C94 .debug$S
C8 .debug$T
10A .drectve
5 .msvcjmc
A .rdata
8 .rtc$IMZ
8 .rtc$TMZ
1B4 .text$mn
我也跑了
nm mylib.lib
我在其他帖子中找到的。您可以看到
_hello
在总结的最后。
D:\Codes\git_folders\my_repository\Cython_test\lib>nm mylib.lib
Debug\mylib.obj:
00000000 N .chks64
00000000 N .debug$S
00000000 N .debug$S
00000000 N .debug$S
00000000 N .debug$T
00000000 i .drectve
00000000 d .msvcjmc
00000000 r .rtc$IMZ
00000000 r .rtc$TMZ
00000000 t .text$mn
00000000 t .text$mn
U @__CheckForDebuggerJustMyCode@4
010471b7 a @comp.id
80000391 a @feat.00
00000000 d __87B4E6C0_mylib@c
00000000 T __JustMyCode_Default
U __RTC_CheckEsp
U __RTC_InitBase
00000000 r __RTC_InitBase.rtc$IMZ
U __RTC_Shutdown
00000000 r __RTC_Shutdown.rtc$TMZ
00000000 T _fnmylib
Debug/examples.obj:
00000000 N .chks64
00000000 N .debug$S
00000000 N .debug$S
00000000 N .debug$S
00000000 N .debug$S
00000000 N .debug$S
00000000 N .debug$S
00000000 N .debug$T
00000000 i .drectve
00000000 d .msvcjmc
00000000 r .rdata
00000000 r .rtc$IMZ
00000000 r .rtc$TMZ
00000000 t .text$mn
00000000 t .text$mn
00000000 t .text$mn
00000000 t .text$mn
00000000 t .text$mn
00000000 R ??_C@_09DEHHIH@hello?5?$CFs?6@
00000008 C ?_OptionsStorage@?1??__local_stdio_printf_options@@9@9
U @__CheckForDebuggerJustMyCode@4
010471b7 a @comp.id
80000391 a @feat.00
00000000 T ___local_stdio_printf_options
00000001 d __101834BA_corecrt_wstdio@h
00000003 d __2F33A99E_examples@c
00000002 d __AD6A91B7_stdio@h
00000000 d __F66CEB67_corecrt_stdio_config@h
U __imp____acrt_iob_func
U __imp____stdio_common_vfprintf
00000000 T __JustMyCode_Default
U __RTC_CheckEsp
U __RTC_InitBase
00000000 r __RTC_InitBase.rtc$IMZ
U __RTC_Shutdown
00000000 r __RTC_Shutdown.rtc$TMZ
00000000 T __vfprintf_l
00000000 T _hello
00000000 T _printf
在我为 x64 系统重建项目后(我必须在 Build > Configuration Manager 中将“Active solution platform”更改为 x64),这是
dumpbin /symbols mylib.lib
的结果.我可以看到
hello
摘要中的功能。
最佳答案
为 x64 重建(静态)库。
您库中的符号名为 _hello
而不是 hello
正如人们对 x64 构建所期望的那样(您的扩展是为 64 位构建的,如日志中所示)。
在 x64 上,MSVC 在编译为 C 代码时不会破坏名称,因此结果符号很简单 - hello
,但它确实破坏了 x86 上的 C 名称(here documentation ,here an example 在 Godbolt.org 上):
__cdecl
-调用约定(如果不使用特殊编译标志,x86 的默认值)添加前缀 _
到将导致符号被调用的名称 _hello
. __stdcall
-调用约定(如果使用 /Gz
编译或明确指定调用约定,即 void __stdcall hello(char *)
)添加前缀 _
到名称和后缀 @
与参数列表中的字节数,即它会导致 _hello@4
. __declspec( dllimport ) void hello(char* a);
会导致(
see live on Godbolt.org):
__imp__hello
(imp
和 hello
之间的两个下划线)用于 x86/32 位,即前缀 __imp_
由于 declspec(dllimport)
和前缀 _
由于 __cdecl
的名称修改在 x86 上。 __imp_hello
(一个下划线介于 imp
和 hello
之间)适用于 x64/64 位,即只有前缀 __imp_
由于 declspec(dllimport)
. dumpbin /header mylibrary.lib
这将产生
machine (x86)
对于 32 位构建:
...
File Type: LIBRARY
FILE HEADER VALUES
14C machine (x86)
...
但是
machine (x64)
对于 64 位构建:
...
File Type: LIBRARY
FILE HEADER VALUES
8664 machine (x64)
此外,当存在机器不匹配时,MSVC-linker 用于产生警告:
mylibrary.lib : warning LNK4272: library machine type 'X86' conflictswith target machine type 'x64'
关于python - "unresolved external symbol"- 在 Windows 上将 Cython 扩展链接到 C 库时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63750020/
我知道这在 Linux 上是可能的。我尝试使用 open("E:", 0); 和 open("E:\\", 0); 但它返回为 -1。我想将 DVD 作为一个大文件来读取,而不是将其用作文件系统。 最
我正在尝试编译一个包含 CUDA 代码的小型库。 我已成功将其编译为共享库,但我真正需要的是静态库。 我有两个源文件: main.c:包含一个用C编写的测试函数。我用gcc编译这个文件 mai
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 这个问题似乎与 help center 中定义的范围内的编程无关。 . 关闭 9 年前。 Improve
我正在使用 MingW 在 Windows 上编写 C 程序,并希望使用 EXPAT XML 库。我想静态编译我的程序,所以我需要静态 .a 库。 有什么方法可以将 EXPAT 编译成 Windows
我想将结果限制为 KEY_HOMEID 等于 journalId 的结果。我已经研究了几天,如有任何帮助,我们将不胜感激。 public Cursor fetchAllNotes(String jou
我一直在寻找这个信息,但是由于可以通过 homebrew 和 pip 安装额外的包和 python 版本,我感觉我的环境很乱向上。此外,很久以前,我用 sudo pip install 和 sudo
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 这个问题似乎不是关于 a specific programming problem, a softwar
我正在尝试合并目录中的所有 *.pdf : gswin64c -q -dNOPAUSE -sDEVICE=pdfwrite -sOutputFile=Total_Files.pdf -dBATCH *
所以我有一个简单的图像缩略图着陆页,例如: 在我的网站上,4 个并排显示在桌面上。如何强制它们在移动设备 View 中成对出现在一行中? 所以:桌面: #### 手机: ## ## 最佳答案
我正在使用 Ubuntu 21.04。我已删除 /usr/bin/python3和 /usr/lib/python3/因为某些软件包在二进制文件中出现错误。我的意思是重新安装python3到一个新的状
是否可以在 Windows 上使用 gyp 将 googles v8 构建为共享库(msvc 2012)?我试过的一切都不起作用。我试过的: python build\gyp_v8 -Dcompone
我需要将 rubygems 从 1.3.5 更新到 1.4.2 但显然 rubygems update 只是将您更新到最新版本 如何更新到 1.4.2? 最佳答案 您可以使用 RVM 安装特定
我还没有找到太多关于它的信息,但我看到了一些提示,表明可以在 iPhone 应用程序中使用 NSTask。如果可能的话,我将如何去做? 我不想越狱我的 iPhone,但我正在开发的应用程序仅供内部使用
我在 UIWebView 中有一个 map 图像。它默认加载在左上角。我希望它在 UIWebView 的中心初始化。 有人知道怎么做吗? 谢谢! 最佳答案 如果 map 图像是页面中唯一的内容,它是否
如何公开 NodePort 类型的服务上网没有 使用类型 LoadBalancer ?我发现的每个资源都是通过使用负载均衡器来完成的。但我不希望负载平衡对我的用例来说既昂贵又不必要,因为我正在运行 p
是否可以将 View 变成可编辑的,例如 this image ? 我知道我可以使用 GridView 来做到这一点。但是,我正在尝试使用 TableRows 来做到这一点,这可能吗? 编辑:我真正想
假设我已将 Heroku 应用程序扩展为 1 个工作进程,但如何指定具有特定名称的 rake 任务应作为工作进程运行? 最佳答案 在你的项目中创建一个 Procfile,然后像这样将 rake 任务放
目前,我在 GitHub 上一个项目的 README.md 文件中使用此 Markdown 文本: See the docs of [testthat][3] on how to write unit
我正在尝试使用一些到 uint8_t 的转换将 IPv4 转换为 IPv6。我知道 IPv4 有 4 个字节,IPv6 有 2 个字节的 16 个无符号整数,但我找不到它们转换的方法。 #includ
我是编程新手,目前正在学习 C。您能帮我解决以下案例吗? 一个例子是,如果用户输入“cbamike”,我想将其分成两个字符串:cba 和 mike。 我尝试了下面的代码,但它不起作用: #includ
我是一名优秀的程序员,十分优秀!