I am working in a small laberinth game using C++. My problem: I like Visual Studio Code for Linux, and when I run my program, I get the following error:
main.cpp:2:10:fatal error: Player.h: No such file or directory
include "Player.h"
I set this project using the following folder structure:
Game
|-------include
|----------GameMap.h
|----------Map.h
|----------MapCell.h
|----------Player.h
|-------src
|----------GameMap.cpp
|----------Map.cpp
|----------MapCell.cpp
|----------Player.cpp
|-------main.cpp
This project ran in another computer I was using, and it runs also when I use codeblocks. BUt since I like to keep working in visual code, I would like to be able to compile and run my C++ code when working from Visual Studio code.
g++ -o main main.cpp
edit:
c_cpp_properties.json
{
"configurations":[
{
"name":"Linux",
"includePath":[
"${workspaceFolder}/**",
"/home/roger/Documents/01.Curso_de_CPP/Projecto/Game_02/Headers/include/**"
],
"defines":[
"_DEBUG"
],
"forcedInclude":[
"/home/roger/Documents/01.Curso_de_CPP/Projecto/Game_02/Headers/include/Player.h"
],
"compilerPath":"/usr/bin/gcc",
"cStandard":"c11",
"cppStandard":"c++17",
"intelliSenseMode":"clang-x64"
}
],
"version":4
}
Although I sti
ll don't understand the Linker problem, I was able to solve it using this:
g++ -o main main.cpp bin/Player.o -std=c++0x -Iinclude
by reading the answer to this post:
What's the point of including -std=c++0x in a G++ compile command?
Related
I have installed gcc-plugin in my Ubuntu 16.10-32 bit and the installation have been done correctly:
>$ gcc -print-file-name=plugin
/usr/lib/gcc/i686-linux-gnu/6/plugin
However, when I try to compile the plugin, I get a huge amount of errors, warning, and exceptions ...
I can not understand what is the reason behind this.
Is it a mistake in the compiling command line? or the installation of the gcc-plugin was not the right way?
I have compiled the gcc-plugin file as follow:
gcc -g -I`gcc -print-file-name=plugin`/include -fpic -shared -o my_plugin.so my_plugin.c
any help?
You have to use the C++ compiler g++. The command line looks otherwise ok, but I don't know your source code, of course.
I'm trying to identify Windows version using IsWindows10OrGreater() and other related functions.
C++, Windows 7 Home Basic, Visual Studio Code v1.36.1, VSCode Extensions - C/C++ for Visual Studio Code, MinGW g++ v8.2.0
Compilation command:
g++ -std=c++11 main.cpp -o file.exe -s -lws2_32 -Wno-write-strings -fno-exceptions -fmerge-all-constants -fpermissive -static-libstdc++ -static-libgcc
I included the version helper header using #include <Versionhelpers.h>, but IntelliSense doesn't recognize it and the build also fails with the error:
fatal error: Versionhelpers.h: No such file or directory
#include <Versionhelpers.h>
I tried including the header in a fresh file and building it, but that didn't work either.
#include <Versionhelpers.h>
int main() {
IsWindowsServer();
return 1;
}
Is there any extension that I need to install in VSCode to get this to work? Or perhaps download the header file (and put it where?)
I used to use Xcode to build and run C++ program.
I use command line to compile the same source code in my Xcode project.
Compiling a individual .cpp file is OK.
Compiling more complicated project(more than one file) is NOT OK.
I have tried gcc, g++, clang, clang++.
The main problem is undefined symbol.
Could you show how to compile complicated project (more than one file) by command line?
From your description, it sounds like you're not using the -c (compile, but don't link) flag. Steps to build your project:
Compile all of the source files:
c++ -c file1.cpp
c++ -c file2.cpp
c++ -c file3.cpp
Link your final executable:
c++ file1.o file2.o file3.o
You can use an optional -o flag to specify the output program name. It probably defaults to a.out.
It would be better to use some kind of build tool (like make, for example) to automate this process, or you'll find it to be very error prone.
I am new to Pandaboard development. I am using CodeSourcery cross compiler to cross compile my application code. My application is a simple 'hello world' app. I am using this for cross-compilation:
arm-none-linux-gnueabi-gcc app.c -o app.out -march=armv5
I am able to generate the app.out.
But when I copied this app.out to my panda board and tried to execute it, I got this exception:
-bash: ./app.out: No such file or directory
How can I resolve this?
This issue is solved using the static linking of shared libraries.The command to do the same is given below.
arm-none-linux-gnueabi-gcc app.c -o app.out -march=armv5 -static
I have a problem with compiling a fortran program with the gfortan complier.
The main program is located in main.f. So, I write in console:
gfortran D:\test\test.f
But it displays me a lot of errors such as:
C:\Users\Efds~1\AppData\Local\Temp\cchFNGgc.o:test.f:<.test+0x3a>: undefined reference to '_gridw_'
C:\Users\Efds~1\AppData\Local\Temp\cchFNGgc.o:test.f:<.test+0x3a>: undefined reference to '_gridz_'
etc.
I think it's because of functions gridw, gridz etc. are located in other *.f files. But I don't know how to link these all together.
Also, I tried to use Compaq Visual Fortran Complier, but it didn't help me.
A basic command for compiling and linking multiple source files into one executable would be
gfortran -o executable source1.f source2.f source3.f
taking care that any .f file you specify is named to the right of any other source files on which it depends. All of this, and much more besides, is well covered in the compiler's documentation.
As noted above, you can compile several files with the same command, but it's quite unusual.
You may prefer first compile to object files (".o") :
gfortran -c gridw.f
gfortran -c gridz.f
And then compile the program
gfortran test.f grodw.o gridz.o
If you have many files to link, it may be interesting to build a library:
ar cru mylib.a gridw.o gridz.o
gfortran test.f mylib.a
If you name your library libSOMETHING.a, you can simply write
gfortran test.f -lSOMETHING