1

I want to use a getenv function from C in my C++ project in Visual Studio 2012.

The code:

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

and then in some function:

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

The error I get:

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
Edward A
  • 2,291
  • 2
  • 18
  • 31
  • Is there a reason you need to call the C function? There is a managed equivalent: http://msdn.microsoft.com/en-us/library/77zkk0b6.aspx – TractorPulledPork May 14 '13 at 19:31

1 Answers1

1

I think for C++ project you can use getenv from <cstdlib>, not C++/CLI one.

Ivan Aksamentov - Drop
  • 12,860
  • 3
  • 34
  • 61