Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

第一章 mainCRTStartup容易误大写Up #1

Closed
huangjj27 opened this issue Feb 5, 2019 · 2 comments
Closed

第一章 mainCRTStartup容易误大写Up #1

huangjj27 opened this issue Feb 5, 2019 · 2 comments

Comments

@huangjj27
Copy link

huangjj27 commented Feb 5, 2019

环境信息

OS: Windows 10
rustc: rustc 1.32.0 (9fda7c223 2019-01-16)
toolchain: stable-x86_64-pc-windows-msvc (default), nightly-x86_64-pc-windows-msvc
c++构建工具: VS2017 Community

例程

# cargo.toml
[package]
name = "blog_os"
version = "0.1.0"
authors = ["huangjj27 <huangjj.27@qq.com>"]
edition = "2018"

[profile.dev]
panic = "abort"

[profile.release]
panic = "abort"

[dependencies]
// main.rs
#![no_std]
#![no_main]

use core::panic::PanicInfo;

#[panic_handler]
fn panic(_info: &PanicInfo) -> ! {
    loop {}
}

// 由于在Windows环境下编译, 故只摘抄Windows所需函数
#[no_mangle]
pub extern "C" fn mainCRTStartUp() -> ! {
    main();
}

#[no_mangle]
pub extern "C" fn main() -> ! {
    loop {}
}

报错信息

error: linking with `link.exe` failed: exit code: 1120
  |
  = note: "C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\Community\\VC\\Tools\\MSVC\\14.14.26428\\bin\\HostX64\\x64\\link.exe" "/NOLOGO" "/NXCOMPAT" "/LIBPATH:C:\\Users\\34937\\.rustup\\toolchains\\nightly-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib" "C:\\Users\\34937\\Desktop\\learning-rust\\blog_os\\target\\debug\\deps\\blog_os-d19438c79a36ae28.4gg7n8zj6teng6ow.rcgu.o" "/OUT:C:\\Users\\34937\\Desktop\\learning-rust\\blog_os\\target\\debug\\deps\\blog_os-d19438c79a36ae28.exe" "/OPT:REF,NOICF" "/DEBUG" "/NATVIS:C:\\Users\\34937\\.rustup\\toolchains\\nightly-x86_64-pc-windows-msvc\\lib\\rustlib\\etc\\intrinsic.natvis" "/NATVIS:C:\\Users\\34937\\.rustup\\toolchains\\nightly-x86_64-pc-windows-msvc\\lib\\rustlib\\etc\\liballoc.natvis" "/NATVIS:C:\\Users\\34937\\.rustup\\toolchains\\nightly-x86_64-pc-windows-msvc\\lib\\rustlib\\etc\\libcore.natvis" "/LIBPATH:C:\\Users\\34937\\Desktop\\learning-rust\\blog_os\\target\\debug\\deps" "/LIBPATH:C:\\Users\\34937\\.rustup\\toolchains\\nightly-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib" "C:\\Users\\34937\\.rustup\\toolchains\\nightly-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\librustc_std_workspace_core-78a7055b7313c664.rlib" "C:\\Users\\34937\\.rustup\\toolchains\\nightly-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libcore-b9ee21a1be63ac89.rlib" "C:\\Users\\34937\\.rustup\\toolchains\\nightly-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libcompiler_builtins-82c426bab9a155a3.rlib"
  = note: Non-UTF-8 output: LINK : error LNK2001: \xce\xde\xb7\xa8\xbd\xe2\xce\xf6\xb5\xc4\xcd\xe2\xb2\xbf\xb7\xfb\xba\xc5 mainCRTStartup\r\nC:\\Users\\34937\\Desktop\\learning-rust\\blog_os\\target\\debug\\deps\\blog_os-d19438c79a36ae28.exe : fatal error LNK1120: 1 \xb8\xf6\xce\xde\xb7\xa8\xbd\xe2\xce\xf6\xb5\xc4\xcd\xe2\xb2\xbf\xc3\xfc\xc1\xee\r\n

error: aborting due to previous error

error: Could not compile `blog_os`.

To learn more, run the command again with --verbose.

参考信息

错误信息出现原因请参考: https://docs.microsoft.com/en-us/cpp/error-messages/tool-errors/linker-tools-error-lnk2001?view=vs-2017

另外找到了 可能 类似的rust连接c问题rust-lang/rust#31233
https://stackoverflow.com/questions/40548334/rust-code-cannot-link-with-a-c-library-compiled-on-windows-because-there-is-an-u

@huangjj27
Copy link
Author

该出错由于mainCRTStartup函数错写成了mainCRTStartUp函数, U字母误大写. 问题已经解决

@huangjj27 huangjj27 changed the title 第一章 例程无法在windows下编译 第一章 mainCRTStartup容易误大写Up Feb 5, 2019
@luojia65
Copy link
Member

luojia65 commented Feb 5, 2019

Ok

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants