Company-clang mode in emacs on windows - c++

I'm having trouble with the last step in getting clang to work with company-mode on emacs.
I have
(setenv "PATH" (concat (getenv "PATH") ";C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\bin\\amd64;C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\bin\\amd64\\amd64;"))
(custom-set-variables
'(company-c-headers-path-system
(quote
("c:/users/chowron/Documents/Development/include" "C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\include" "C:\\Program Files (x86)\\Windows Kits\\8.1\\Include\\shared" "C:\\Program Files (x86)\\Windows Kits\\8.1\\Include\\um")))
'(company-clang-arguments
(quote
("-I \"C:\\\\Program Files (x86)\\\\Microsoft Visual Studio 14.0\\\\VC\\\\include\"" "-I \"c:\\\\Program Files (x86)\\\\Windows Kits\\\\10\\\\Include\\\\10.0.10586.0\\\\ucrt\"" "-I \"c:\\\\users\\\\chowron\\\\Documents\\\\Development\\\\include\"")))
'(company-clang-executable
"C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\ClangC2\\bin\\amd64\\clang.exe")
'(company-clang-insert-arguments nil))
In a simple program like
#include <iostream>
#include <string>
int main(int argc, char** argv) {
std::string food;
food. // Completion at point here
}
I see in clang-error
clang failed with error 1:
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\ClangC2\bin\amd64\clang.exe -fsyntax-only -Xclang -code-completion-macros -x c++ -I "C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\include" -I "c:\\Program Files (x86)\\Windows Kits\\10\\Include\\10.0.10586.0\\ucrt" -I "c:\\users\\chowron\\Documents\\Development\\include" -Xclang -code-completion-at=-:9:8 -
<stdin>:1:10: fatal error: 'iostream' file not found
#include <iostream>
^
1 error generated.
Running this on CMD.exe, however seems to work fine. Using stdin to input the file with a CTRL-Z at the end gives a bunch of warnings and eventually
...
COMPLETION: pop_back : [#void#]pop_back()
COMPLETION: push_back : [#void#]push_back(<#char _Ch#>)
COMPLETION: rbegin : [#reverse_iterator#]rbegin()
COMPLETION: rbegin : [#const_reverse_iterator#]rbegin()[# const#]
...
So I think I have the command line args and paths set up ok within emacs, but there is some setting or emacs function missing?

I found that the issue was in how the include "-I" paths were set. For anyone who might encounter the same problem.
In the .emacs setup, you have to write it like
(quote
("-IC:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\include" "-Ic:\\Program Files (x86)\\Windows Kits\\10\\Include\\10.0.10586.0\\ucrt" "-Ic:\\users\\chowron\\Documents\\Development\\include" "-v")))
There are no quotes around the 'Program Files (x86)...' paths. Let clang do the interpretation.
As an extra note, this works with the clang bundled with VS2015 Release 2 and upwards at least. It should work with official releases too.

Related

Using Qt with Visual Studio Code (Windows)

The following are installed:
Visual Studio Code (1.45.1)
Visual Studio 2019 Community (in order to use the MSVC cl.exe compiler)
Qt 5.15.0 (installed to C:\Qt)
Visual Studio Code has been launched after running Visual Studio Command Prompt so that the environment is set correctly for cl.exe. The ms-vscode.cpptools extension has been installed in Visual Studio Code and includePath is set to:
"includePath": [
"${workspaceFolder}/**",
"${INCLUDE}",
"C:/Qt/5.15.0/msvc2019_64/include/**"
],
This file hw.cppcompiles and runs fine:
#include <iostream>
int main()
{
std::cout << "Hello world!";
return 0;
}
The command used in tasks.json is:
"command": "cl.exe",
"args": [
"/Zi",
"/EHsc",
"/Fe:",
"${fileDirname}\\${fileBasenameNoExtension}.exe",
"${file}"
],
Alternatively, from the in-built Terminal inside Visual Studio Code, the command "cl /EHsc /MD /O2 hw.cpp /link /out:hw.exe" compiles everything correctly and hw.exe can be executed.
But when I attempt to use Qt as follows it fails to compile:
#include <QString>
int main()
{
QString test("Hello world!");
qDebug() << test;
return 0;
}
The compiler reports "fatal error C1083: Cannot open include file: 'QString': No such file or directory". IntelliSense does find QString.h, which opens when I press Ctrl and click QString (at the top).
What am I missing?
UPDATE
Thanks to comments from #rioV8, I've investigated /link options for cl.exe. The task arguments have been updated to:
"args": [
"/EHsc",
"/MD",
"/O2",
"/IC:\\Qt\\5.15.0\\msvc2019_64\\include",
"/IC:\\Qt\\5.15.0\\msvc2019_64\\include\\QtCore",
"${file}",
"/link",
"/LIBPATH:C:\\Qt\\5.15.0\\msvc2019_64\\lib",
"Qt5Core.lib",
"qtmain.lib",
"/OUT:${fileDirname}\\${fileBasenameNoExtension}.exe"
],
This has improved things slightly. hw.cpp now compiles and generates hw.obj, but now I get linker errors (one for each .lib):
warning LNK4272: library machine type 'x64' conflicts with target machine type 'x86'
This is followed by fatal error LNK1120: 2 unresolved externals.
Getting closer, but still not linking.
There has been a detailled guide on the KDAB blog recently.
Overview of VS Code for Qt developers:
https://www.kdab.com/using-visual-studio-code-for-writing-qt-applications/
Technical guide:
https://www.kdab.com/using-visual-studio-code-for-qt-apps-pt-1/
https://www.kdab.com/using-visual-studio-code-for-qt-apps-pt-2/
The steps in the technical guide look very similar to the issues you are describing ;-)

Can't include mysql

I have been trying for a while now. I have been asked to do a few modifications on a big program, and it requires a lot of libs. All of them were succesfully added, except mysql.
I downloaded the libs several times and tried a lot of times.
I am on Windows using Netbeans and C++.
The test I decided to do is simple: create an empty program and try to include mysql. I didn't have any success:
#include <cstdlib>
#include <mysql/mysql.h>
using namespace std;
int main(int argc, char** argv) {
return 0;
}
This program won't work even if I replace #include <mysql/mysql.h> with #include <mysql.h>.
The error NetBeans gives me is the following:
main.cpp:15:25: fatal error: mysql/mysql.h: No such file or directory
These images show how I altered the project options on Linker and C/C++ options:
Parameters
The folder showing on the C image does contain a mysql.h, i triple checked twice.
I also have added the paths with includes to CodeAssistance.
Many similar questions were left unanswered for years now on several forums, even on stackoverflow, and I can't seem to work this out. This thread may have a final answer to those of us who stumble upon this.
It is not able to find the file
At this point, your program would be pointing to something like this:
cl /I "C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include"
mysql1.c
So you needed to include the directory that contains mysql.h as well. So the above would changed to:
cl /I "C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include"
/I "C:\Program Files\MySQL\MySQL Server 5.5\include" mysql1.c
verify the header file exist in the path /usr/include/mysql/mysql.h or installed some where else. If you have installed the header files somewhere else ( add that location with -I/.

Cannot run Hello World C++ program

I am just starting C++ and downloaded a compiler and an IDE, both eclipse, and tried to make my first C++ program. I use the Hello World C++ Makefile Project, and add the all the stuff on the next page. I then build the program, and the build says this:
12:30:00 **** Build of configuration Default for project HelloWorld! **** make all Cannot run program "make": Launching failed
Error: Program "make" not found in PATH PATH=[C:/Program Files
(x86)/Java/jre1.8.0_91/bin/client;C:/Program Files
(x86)/Java/jre1.8.0_91/bin;C:/Program Files
(x86)/Java/jre1.8.0_91/lib/i386;C:\ProgramData\Oracle\Java\javapath;C:\Program
Files\Common Files\Microsoft Shared\Windows Live;C:\Program Files
(x86)\Common Files\Microsoft Shared\Windows
Live;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;c:\Program
Files (x86)\ATI Technologies\ATI.ACE\Core-Static;c:\Program Files
(x86)\Common Files\Roxio Shared\DLLShared\;c:\Program Files
(x86)\Common Files\Roxio Shared\12.0\DLLShared\;C:\Program Files
(x86)\Windows Live\Shared;c:\Program Files (x86)\Microsoft SQL
Server\100\Tools\Binn\;c:\Program Files (x86)\Microsoft SQL
Server\100\DTS\Binn\;C:\Users\Jen\Desktop\eclipse;] 12:30:00 Build
Finished (took 122ms)***
I run the program, and it says:
Launch failed. Binary not found.
This is the code for the program:
#include <stdio.h>
#include <stdlib.h>
int main(void) {
puts("Hello World!");
return EXIT_SUCCESS;
}
There are two errors, too:
Function "puts" couldn't be resolved.
Symbol "EXIT_SUCCESS" couldn't be resolved.
Thanks in advance!
Nate N.
/////////////////////////////////////////////////////////////////////////
I followed the advise of user4581301 and the code now says this:
#include <iostream>
using namespace std;
int main() {
cout << "Hi World" << endl; // prints Hi World
return 0;
}
The build looks like this:
13:22:26 **** Rebuild of configuration Debug for project HiWorld ****
Info: Internal Builder is used for build
g++ -O0 -g3 -Wall -c -fmessage-length=0 -o "src\HiWorld.o" "..\src\HiWorld.cpp"
g++ -o HiWorld.exe "src\HiWorld.o"
13:22:27 Build Finished (took 835ms)
But now the program, although it does run, doesn't print anything.
Thanks in advance,
Nate N.
Launch failed. Binary not found.
well this is shown because you have 2 errors.
any error means = no binary compiled/linked
no binary compiled/linked = cant launch something which doesnt exist
solution = fixing the errors
#include #include
^ also this is not valid
Cannot run program "make": Launching failed Error: Program "make" not found in PATH
Kaboom! No make, no build, no binary to run.
Some compilers don't ship with Make out of the box, but I don't see any signs of a compiler toolchain in your path at all.
Eclipse is an IDE with support for a wide variety of different compilers. as a result it does not ship with one. Since the error message shows you are building on Windows, your simplest option is one of the many MinGW variants. And Since you are just starting, I recommend starting off with the plain-vanilla MinGW as Eclipse requires next to no extra configuration to use it.
Just make sure you follow the instructions to install msys along with MinGW to get make.

Cannot run program makefile when compiling a c++ program with NetBeans and MinGW gcc

I'm trying to compile a simple "Hello" program on Windows 7 x64:
#include <cstdlib>
#include <iostream>
using namespace std;
int main(int argc, char** argv) {
cout << "Hello" << endl;
return 0;
}
And getting an error in the NetBeans IDE when compiling:
CLEAN SUCCESSFUL (total time: 126ms)
D:\GDrive\CS\Cpp\NetBeans_Cpp\TNB_cpp\Tut1_10_HelloWorld\Makefile -f nbproject/Makefile-Debug.mk build/Debug/MinGW-Windows/main.o
Cannot run program "D:\GDrive\CS\Cpp\NetBeans_Cpp\TNB_cpp\Tut1_10_HelloWorld\Makefile" (in directory "D:\GDrive\CS\Cpp\NetBeans_Cpp\TNB_cpp\Tut1_10_HelloWorld"): CreateProcess error=193, %1 is not a valid Win32 application
COMPILE FILE FAILED (exit value -2, total time: 16ms)
My PATH env variable looks like this:
%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\;C:\Program Files\Intel\WiFi\bin\;C:\Program Files\Common Files\Intel\WirelessCommon\;F:\Program_Files\JDK\bin;C:\Program Files\Microsoft\Web Platform Installer\;C:\Program Files (x86)\Microsoft ASP.NET\ASP.NET Web Pages\v1.0\;C:\Program Files (x86)\Windows Kits\8.0\Windows Performance Toolkit\;C:\Program Files\Microsoft SQL Server\110\Tools\Binn\;F:\Program_Files\MinGW\bin;F:\Program_Files\MinGW\msys\1.0\bin;
The last two varibles being probably the most important since they pertain to the MinGW. My ideas is that something is missing in the PATH, but maybe its not where the problem hiddes.
Thanks.
It looks as if some settings are wrong.
Look at your Netbeans settings : Toolchain : Make Command
looking after one of the files.
make.exe
mingw32-make.exe.
In the directories, for example,
c:\msys\1.0\bin
c:\MinGW\bin
goto -> options -> c/c++ -> Build Tools
and check if the settings match this

MS link fails from gnu make, but works from cmd line

Recently my gnu makefile stopped linking my C++ project. I had made some changes. I have copied the link line out and run it from a batch file. It builds fine. But the same line strangely fails when I run make. The error it gives is:
LINK : fatal error LNK1181: cannot open input file 'user32.lib'
which has to be a red herring because from the same command line prompt, running the link command succeeds. I am beginning to suspect GNU make. This used to work from within make but I made a few additions and changes to the makefile to get it building on Linux which seemed to introduce the problem.
I am using :
GNU Make 3.80
MS Visual C++ Linker 10.00.40219.01
on Windows XP.
My LIB and LIBPATH both include the path to the SDK directory which contains the libraries. My link command is as follows:
link C:\SDL-1.2.14\lib\SDL.lib C:\SDL-1.2.14\lib\SDLmain.lib C:\SDL-1.2.14\lib\SDL_image.lib C:\SDL-1.2.14\lib\SDL_ttf.lib C:\SDL-1.2.14\lib\SDL_mixer.lib C:\SDL-1.2.14\lib\SDL_net.lib ../../build/lib/sdlhal.lib user32.lib gdi32.lib kernel32.lib oldnames.lib wsock32.lib advapi32.lib comdlg32.lib comctl32.lib wsock32.lib winmm.lib netapi32.lib OpenGL32.lib glu32.lib /nologo /incremental:no -subsystem:console /PDB:../../build/bin/Prog.pdb /OUT:../../build/bin/Prog.exe /MAP:../../build/bin/Prog.map ../../build/Prog/intr/util.obj ../../build/Prog/intr/objwithvel.obj ../../build/Prog/intr/rock.obj ../../build/Prog/intr/explosion.obj ../../build/Prog/intr/ship.obj ../../build/Prog/intr/photon.obj ../../build/Prog/intr/world.obj ../../build/Prog/intr/test.obj ../../build/Prog/intr/main.obj
EDIT: Bit of progress with C++ program below. My Environment variables were:
LIB=C:\Program Files\Microsoft Visual Studio 10.0\VC\LIB;C:\Program Files\Microsoft Visual Studio 10.0\VC\ATLMFC\LIB;C:\Program Files\Microsoft SDKs\Windows\v7.0A\lib;
LIBPATH=C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319;C:\WINDOWS\Microsoft.NET\Framework\v3.5;C:\Program Files\Microsoft Visual Studio 10.0\VC\LIB;C:\Program Files\Microsoft Visual Studio 10.0\VC\ATLMFC\LIB;
But when printed out by program run from within make, they are:
LIB=.lib
LIBPATH=C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319;C:\WINDOWS\Microsoft.NETFramework\v3.5;C:\Program Files\Microsoft Visual Studio 10.0\VC\LIB;C:\Program Files\Microsoft Visual Studio 10.0\VC\ATLMFC\LIB;
Based on your description of the value of LIB, I suspect that you have simply set the "LIB" variable in your makefile (to ".lib"). In standard GNU make (actually, all versions of make) all the environment variables are imported into make as make variables when make starts up (there are exceptions, such as SHELL, which are handled differently).
Whenever make invokes a command, all the current values of variables that were imported are written out to the environment of the child process.
Put another way, any variable that make read from its environment is considered to be marked for export when make runs any command from a recipe.
So if you have a makefile like this:
LIB = .lib
all: ; #echo "LIB = %LIB%"
and you run it like this:
> set LIB=C:\foo;C:\bar
> make
then the output will be "LIB = .lib", not "LIB = C:\foo;C:\bar"
I suspect that your LIB and LIBPATH variables aren't set the way you think they are when link is invoked from make.
Try creating your own link.exe program that gets invoked from make and dumps the command line and environment. That'll tell you for certain whether or not the variables are set correctly by the makefile.
#include <stdlib.h>
#include <stdio.h>
int main( int argc, char** argv, char** env)
{
int i = 0;
for (i = 0; i < argc; ++i, ++argv) {
if (!(*argv)) {
*argv = "(null)";
}
printf( "arg[%d]: \"%s\"\n", i, *argv);
}
puts("\nENVIRONMENT...\n");
while (*env) {
printf( "%s\n", *env);
++env;
}
return 0;
}
Also check that there aren't unquoted spaces in the wrong place in the link command line. While it would seem to be unrelated to the error you mention in the question (and is probably really just a cut/paste error), the link command line you gave has a space in the middle of the path/file name for explosion.obj.
This is likely to be a path issue. Are you using the mingw version of GNU make, or the Cygwin version?
One way to debug this is to put an echo $LIB and echo $LIBPATH command into the make recipe to confirm that these are getting set as you expect.