静态库调用时的访问冲突
作为问题MSVC 未解析的外部符号链接可执行文件的扩展。 A
包含一个类 P
,该类具有两个成员函数 F
和 G
,并且还包含一个全局 P MyP
。我正在尝试从可执行文件 T
调用函数 MyP.F
。我终于通过了链接部分,但现在它在运行时失败,但出现异常。
A.cpp
struct P {
void F();
void G();
} MyP;
P::F() {
}
P::G() {
}
int main() {
MyP.F();
MyP.G();
}
T.cpp
struct P {
void F();
void G();
} MyP;
int main() {
MyP.F();
MyP.G();
}
我可以在 Visual Studio 2008 中调用 F
的行中的 T
中放置一个断点,但是当我按下按钮单步执行时,或者要跳过,我得到一个异常 First-chance exception at 0xfe5ca589 in A.exe: 0xC0000005: Access Reading location 0xfe5ca589
。当我查看调用堆栈时,它显示
fe5ca589()
A.exe!G() + 0x60a6 字节
[下面的框架可能不正确和/或丢失,没有为 A.exe 加载符号]
这两个项目都是同一 Visual Studio 解决方案的一部分,并且 A
已正确设置为 T 的依赖项
,似乎链接正确,但我无法进入它。有谁知道如何让 Visual Studio 加载 A
的符号,以便我可以进入它并找到错误? (或者如果某些链接很有趣导致错误?)
As an extension of question MSVC unresolved external symbol linking executables. A
contains and a class P
with two member functions F
and G
, and also contains a global P MyP
. I'm attempting to call functions MyP.F
, from Executable T
. I finally got past the linking part, but now it fails at runtime with the exception.
A.cpp
struct P {
void F();
void G();
} MyP;
P::F() {
}
P::G() {
}
int main() {
MyP.F();
MyP.G();
}
T.cpp
struct P {
void F();
void G();
} MyP;
int main() {
MyP.F();
MyP.G();
}
I can put a breakpoint in T
at the line where it calls F
in Visual Studio 2008, but when I press the button to step in, or to step over, I get an exception First-chance exception at 0xfe5ca589 in A.exe: 0xC0000005: Access reading location 0xfe5ca589
. When I look at the call stack, it shows
fe5ca589()
A.exe!G() + 0x60a6 bytes
[Frames below may be incorrect and/or missing, no symbols loaded for A.exe]
Both projects are part of the same Visual Studio solution, and A
is properly set as a dependancy for T
, and seems to be linking correctly, but I can't step into it. Does anyone have insights how to make Visual Studio load the symbols for A
so I can step into it and find the error? (Or if something is linked funny causing the error?)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
可执行文件没有允许它们在备用地址加载的元数据,并且
A.EXE
无法加载到T.EXE
的所需地址,因为 < code>T.EXE 的代码已经存在。您也许可以通过更改A.EXE
的默认加载地址(构建它时,它是一个链接器选项)来解决此问题,但正确的解决方案是使用 DLL。< /strike> (已确认,不,你不能)导出自提供
.EXE
文件以允许插件DLL 调用主应用程序中的函数。它们并不意味着允许像 DLL 一样加载.EXE
。Executables don't have the metadata allowing them to be loaded at an alternate address, and
A.EXE
can't load intoT.EXE
at its desired address, becauseT.EXE
's code is already there.You might be able to work around this by changing the default load address of(Confirmed, no you can't)A.EXE
(when building it, it's a linker option), but the correct solution is to use a DLL.Exports from
.EXE
files are provided to allow plugin DLLs to call functions in the main application. They aren't meant to allow loading the.EXE
like it was a DLL.