0

How to fix "CL.exe" Not Compiling C++??

I have created a standalone python project on my desktop, keep in mind that I'm not using Visual Studio, I am in fact using pythontowin. I would like to compile a C++ file into a DLL to use for my python project. But I am getting weird unexplained errors when trying to compile with cl.exe.

Here is my C++ file.

#include <Windows.h>
#include <iostream>

using namespace std;

void Thread() {
    cout < "Hello World" < endl;
    Sleep(1000);
}

BOOL DllMain(HINSTANCE hDll,DWORD dwReason, LPVOID) {
    if (dwReason == DLL_PROCESS_ATTACH) {
        CreateThread(0, 0, (LPTHREAD_START_ROUTINE)Thread, 0, 0, 0);
    }
    return TRUE;
}

Command used for cl.exe: cl.exe /std:c++14 /LD ./../LibraryXdll.cpp

And this is the error I am getting: fatal error C1034: Windows.h: no include path set

If anyone could solve this error I would be very thankful and I can finish off my project thanks for the help. Regards RanOutOfQuestions!

  • 1
    Hi RanOutOfQuestions and welcome to Stack Overflow! I don't think that the python stuff has anything at all to do with your question - you just are having trouble compiling the `c++` code. Am I right, or am I missing something? – Max von Hippel Jun 05 '18 at 04:11
  • I am good at python and vague in C++ so I am making python project using c++ DLLs. –  Jun 05 '18 at 04:14
  • 2
    "no include path set" usually means that `Windows.h` is not in your include path(s). You probably need to track down where that file is and specify an argument to search those include paths as well. With regular compilers this is `-I` but `cl.exe` probably differs. – tadman Jun 05 '18 at 04:14
  • Now when I try: cl.exe /std:c++14 /LD /FI./../Windows.h ./../LibraryXdll.cpp it gives me the same error: fatal error C1034: ./../Windows.h: no include path set. –  Jun 05 '18 at 04:22
  • Possible duplicate of [fatal error C1034: windows.h: no include path set](https://stackoverflow.com/questions/931652/fatal-error-c1034-windows-h-no-include-path-set) – Claies Jun 05 '18 at 04:37

1 Answers1

0

Taking up on Tadman's comment:

It looks like you didn't set up your environment variables for use of cl.exe If you have gotten cl.exe, you should also have a Bat-File called vcvarsall.bat or vcvars32.bat / vcvars64.bat. In case of a default Visual studio installation these can be found under "Program Files (x86)\Microsoft Visual Studio\version number\produkt type, e.g. community\VC\Auxiliary\Build".

Run the appropriate version of vcvars... (32 or 64 bit, or specifiy the flag for vcvarsall, see docs), and your include paths for THAT SESSION will be set (inside that terminal, if you close it the changes are lost again and you have to call vcvars again next time).

EDIT: Microsoft documentation on vcvars

You can work around that Reset by calling vcvars every time before executing the compiler, though this isn't a beautiful solution

  • Thx ill try this then. Do you have a syntax or link to docx? –  Jun 05 '18 at 06:48
  • I have no idea what I am sup post to use vcvars.bat for the only information I have received is that I need to use it before compiling? –  Jun 05 '18 at 07:04
  • I just assume you use windows, since you use cl.exe. I've added a link to the official doc in the original answer. Vcvars sets environment variables for you, like Include-paths, lib-paths, ... Otherwise your compiler just does not know where windows.h is supposed to be, and can not find it. –  Jun 05 '18 at 08:12