Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
I am merging two complicated program, one written in c and the other in c++.
Here is a simplified situation.
My main program is written in c (main.c).
#include <stdio.h>
#include "test.h"
int main()
{
printf("test!\n");
}
where test.h is the header of test.cpp, which is another program written by others in cpp.
test.h
#include <vector>
int test();
test.cpp
#include "test.h"
int test()
{
return 1;
}
I try to compile main.c using the following command:
gcc -c main.c -o main.o -lstdc++
But I get the following error:
fatal error: no such file or dirctory #include
I don't want to change the codes of my main.c or test.cpp since they are much more complicated than that in this simplified example.
I am new to gcc, anyone can help to solve this problem?
Many thanks.
You should compile with g++, not gcc because it's C compiler and <vector> is a C++ header file (not mentioning <vecotr> which is a typo)
If you have to use C compiler, you have to remove all C++ dependencies from header files which are included from the C sources.
That's a typo: replace
#include <vecotr>
^^^
with
#include <vector>
Edit: plus you should compile with g++, not gcc since you're including a C++ header file.
Related
This question already has answers here:
Merge C++ files into a single source file
(8 answers)
Closed 2 years ago.
In the context of a coding contest, I must copy/paste all my C++ code in a single html input form, the code being compiled remotely. With the code getting bigger, I'd like to split the code into several files.
So, I have several C++ source files, one is main.cc and some others headers such as f.h.
I'd like these source files to be concatenated in a single source file allinone.cc with so that i can compile with clang++ allinone.cc.
I guess this can be achieved using clang preprocessor.
A minimal example would be:
main.cc
#include <iostream>
using namespace std;
#include "f.h"
int main() {
f();
}
f.h
#pragma once
#include <iostream>
using namespacestd;
void f() {
cout <<
}
The closest I could get is with :
clang -E -nostdinc main.cc | grep -v "^#" > allinone.cc
which produces:
#include <iostream>
^~~~~~~~~~
1 error generated.
using namespace std;
using namespacestd;
void f() {
cout <<
}
int main() {
f();
}
The -nostdinc option successfully avoids including code from standard includes. However, the original #include <iostream> disappears and the namespace specification is repeated.
Is there a way to invoke clang preprocessor to achieve the concatenation described in a straight forward manner?
clang -nostdincdoes another thing, not what you expect. This key disables the standard include directories from the include search paths. So, you get the error since the preprocessor is unable to include the file -nostdinc, could not find it in the known include search paths.
What you want is impossible to achieve. You should use cat your files and clean the result manually or use a special software that can remove #include. I suggest you just use a combinations of grep, sort, uniq and place removed and filtered #include into the top of the concatenated file.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 3 years ago.
Improve this question
I am new to Visual Studio for C++ (just moved in from Ubuntu g++ / gcc).
I am having trouble since Visual Studio does not seem to recognize
std::vector, std::complex<>, std::complex<double>, etc.
That all worked fine for Linux. How to do incorporate these in Visual Studio?
You probably copy pasted functions but forgot to include appropriate headers (newbie mistake).
Just try this:
#include <iostream>
#include <vector>
#include <complex>
using namespace std;
int main()
{
cout<<"Hello World";
return 0;
}
This question already has answers here:
the procedure entry point __gxx_personality_v0 could not be located
(5 answers)
Closed 4 years ago.
I am writing a simple small program in c++ to test vectors. The following code works well and output hello to the cmd.
The steps I follow are:
g++ filename.cpp to compile
.\a.exe to run
#include <iostream>
#include <vector>
using namespace std;
int main()
{
cout<<"hello";
return 0;
}
However, when I declare a vector, the hello does not show and the program seem to not working at all.
#include <iostream>
#include <vector>
using namespace std;
vector<int> a;
int main()
{
cout<<"hello";
return 0;
}
I do not get any error message while compiling. But I do get a certain message about no entry point when I run outside the cmd.
The procedure entry point _ZNKSt9baisc_ioslcSt11char_traitslcEEcvbEv
could not be located in the dynamic link library
I searched on google and stack overflow but could not find a solution to my problem.
For anyone who would read this later on, I had something called gtk installed and defined in the environment path variables and it seems like it was colliding with MinGW. Everything runs smooth by writing:
g++ ex1.cpp -static-libgcc -static -static-libstdc++
The problem is likely caused by the fact that the DLL containing the function the program is trying to access (_ZNKSt9baisc_ioslcSt11char_traitslcEEcvbEv here) is not found by Windows when it tries to execute your program.
There are a few solutions for this :
Static linking with the C++ library (--static-libstdc++) (this will directly link the C++ library into your executable (this may make your program bigger))
Putting the libstdc++ dll in your program folder (you should be able to find it somewhere in the compiler install folder)
Adding the path to the libstdc++ dll to the global PATH variable (If you want to know more about adding to the PATH, see here) so that the dll will be found for any executable running on your computer
Doing any of these should fix your problem.
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 6 years ago.
Improve this question
#include <iostream>
#include <stdlib.h>
#include <mmsystem.h>
#include <string>
#include <windows.h>
#pragma comment (lib, "winmm.lib")
using namespace std;
int main() {
PlaySound(TEXT("Happy Birthday To You.wav"), NULL, SND_SYNC);
system("pause");
return 0;
}
C:\Program Files (x86)\CodeBlocks\MinGW\include\mmsystem.h|905|error: 'DWORD' does not name a type|
C:\Program Files (x86)\CodeBlocks\MinGW\include\mmsystem.h|906|error: 'UINT' does not name a type|
C:\Program Files (x86)\CodeBlocks\MinGW\include\mmsystem.h|907|error: typedef 'UINT' is initialized (use decltype instead)|
It just came up tons of the errors in the header file like these, I linked to -lwinmm and checked the library, it still pops up.
PS I am using code blocks.
You need to include windows.h before mmsystem.h. windows.h should be first in your includes. mmsystem.h uses types defined in windows.h (including DWORD and UINT).
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 4 years ago.
Improve this question
This is the c++ code I want to run on my computer: http://pastebin.com/66BEyTWK
On the university computer, this code displays a white square. But when I try to run it on my computer all I get is a blank screen.
I read on the opengl faq that the problem might be that I am linking with the wrong combination of opengl libraries.
The include part of the code suggests that I need to link glm, glew and freeglut.
#include <iostream>
#include <GL/glew.h>
#include <GL/freeglut.h>
#include <glm/glm.hpp>
I read that it is not necessary to link glm, because it is only a header file. So this is the compile statement I came up with:
g++ -o main white_square.cpp -lGL -lglut -lGLEW
At my university they have setup a custom makefile which I can't get much sense out of: http://pastebin.com/3DxST3Xs