c++ - Visual C++ 2012 中的 getenv

标签 c++ c visual-studio-2012 extern getenv

我想在 Visual Studio 2012 的 C++ 项目中使用 C 中的 getenv 函数。

代码:

extern "C" System::SByte^ getenv(const System::SByte^ name);

然后在一些函数中:

String^ h1 = "HOMEDRIVE";
const System::SByte^ c1 = dynamic_cast<const System::SByte^>(h1);
getenv(c1);

我得到的错误:

Error   11  error LNK2019: unresolved external symbol "extern "C" class System::SByte ^ __clrcall getenv(class System::SByte const ^)" (?getenv@@$$J0YMP$AAVSByte@System@@P$ABV12@@Z) referenced in function "public: void __clrcall Kameleon::Form1::createConfig(void)" (?createConfig@Form1@Kameleon@@$$FQ$AAMXXZ)   C:\Users\Michal\Desktop\Kameleon\Kameleon\Kameleon\Kameleon.obj Kameleon

最佳答案

我认为对于 C++ 项目,您可以使用 getenv from <cstdlib> ,不是 C++/CLI。

关于c++ - Visual C++ 2012 中的 getenv,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16550932/

相关文章:

c++ - bitset 不适用于某些数字

c++ - cppcheck 在 const std::string[] 上抛出警告

c - pthreads 没有真正的加速

VB.Net Google Page Speed Api 如何将策略更改为移动设备

visual-studio-2012 - 括号/引号中的 Visual Studio 选项卡?

c++ - 如何使用 CMake 生成面向 Windows XP 的 Visual Studio 2012 项目?

c++ - 使用 SSE2 和 AVX2 编译库

c - 程序在奇怪的地方打印垃圾值 (C)

c++ - 关闭cin与C scanf同步的弊端

c++ - Mingw+MSYS 中 libevent 的静态编译错误