I'm having a problem with C++. Specifically, I am just trying to start out and well I am having little to no luck. So far I have downloaded and tried two compilers. I've tried to use:
Clang - I've tried to install it and it failed to install. I got two
error messages when I tried that:
Failed to find MSBuild toolsets directory
Failed to open files while installing
Then I tried to install Dev C++ and had a bit more luck, yet still
ran into problems. I just couldn't get the "Hello World!" file to
compile and run. I got the following error messages with that:
[linker error] undefined reference to '__dyn_tls_init_callback'
[linker error] undefined reference to '__cpu_features_init'
[linker error] undefined reference to '__setargv'
There are many different compilers and other tools that can be used for developing and debugging. Setting up a development environment can be a challenge especially if you are learning.
An IDE - Integrated Development Environment consists of an editor, a build tool, compiler and linker, debugger and probably more tools. Compiler takes your code + system header files and produces object files. Linker takes object files + system lib files and produces executable.
You need to get a C++ IDE installed and working so you can learn some C++ without worrying too much (yet) about building compiling linking. But you will need to learn about each component!
I do not know of an IDE that comes with a very simple install! In the old days of TurboC++ and BorlandC we had it good, kindof! Google for https://www.google.ie/search?q=c%2B%2B+ide+for+windows Eclipse and Netbeans are big and need some setup (install language compilers and libs) before you get productive. But they are very popular. E.g. instructions steps to get up and running with Eclipse and C++ https://www3.ntu.edu.sg/home/ehchua/programming/howto/EclipseCpp_HowTo.html
If you are learning can you start with an interpreted language like python first? Before diving into C++. Learning c before C++ might be a good idea.
Related
I am programming a chess engine with 2 friends and it is getting very strong (above 3000 Elo).
We have written the code in C++ and compile using make. For some reason the normal installer for MinGW did not do what it was supposed to so I went with msys2 and installed all the requires packages using msys2.
I am not familiar with compiling C++ under windows and here is the problem:
When I compile the program using the Git Bash or powershell, it compiles nicely (except for a few warnings) using: make native
The issue is the way I need to execute the program:
It does not work if I run using powershell or cmd
It does not work if I double click it (see the error message below)
It does only work if invoked from a bash
If you are not familiar with german, this is a rough translation:
The procedure entry point "..." was not found in the DLL "..."
We have provided a makefile which can build different versions (native, release (for multiple hardwares)). Running a non-native version like Koivisto_3.9-x64-windows-popcnt-avx.exe does run by simply double clicking it.
Also the file sizes are very different:
native: 600kb
non-native: 3100kb
The entire project is on github: Koivisto Chess Engine
And the makefile can be found here: Makefile
I wonder why there seems to be that difference and why the native version only runs within a bash. I am very happy if someone could explain this behaviour to me and potentially even tell me a way to fix this.
I am very happy for any advice!
Greetings,
Finn
I want to create an MP3 player on my Raspberry Pi (OS: Raspbian). The problem is, that i don't have any experience with Linux programming, and I'm having a huge problem with project configuration, becouse of cross platform compiling. I want to add two liblaries:
mpg123
libao
I'm able to compile the code on linux machine with gcc -O2 test.cpp -lmpg123, but I can't force Visual Studio to make see those libs.
I'm also having a problem with using wiringPi lib while I'm trying to remote debugging my program, since I have to run it as root for GPIO configuration. Is there any way for any way to force Visual Studio to run my compiled code with root privilages?
Personally I come from a long history of C/C++/MFC/Windows programming with no Linux experience at all. I started programming for the Raspberry a year or so ago, when I got one from my son for my birthday. With a C/C++ history it's really not that hard, but you just have to read in a bit because on Linux a lot is the same, and a lot isn't :). Just read and read and in time, you're an experienced Linux programmer! It takes some time I'm afraid.
So, I'm sort of an experienced newbie on this I think :). I found a lot of info on www.die.net (and other Linux man pages). If you search there for a function, say printf(), look at the (3) pages - they explain how you should use 'm.
But although VS2017 does a really good job on this, it's not always going as smooth as you would like. Sometimes it's just necessary to reboot your Raspberry, restart VS and try again. The Linux cross-compiling is quite new in VS and isn't perfect yet.
A few tips:
Use a Raspberry with a fresh Stretch image to start with. Of course after a sudo apt-get update && sudo apt-get -y upgrade.
Set the debugger in Visual Studio to gdb instead of gdbserver. This will prevent certain debugging problems.
Place all your source files (.h and .cpp) in the main folder of your project alongside the main.cpp. If you place them in different directories and then include in your project, you can debug your program but you won't be able to step through.
Start simple and debug your program often when you're developing. Don't add too much code before your next check. In a cross-compile setup there are just a lot more things than normal that can (and will) go wrong.
VS2017 has default Linux include files in C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\IDE\VC\Linux\include. If you need others, place them in a folder of you own and include the path.
With cross-compiling VS itself doesn't do any compiling, you use it to maintain your project. When the project has to be compiled, all necessary files are copied to the Raspberry and the compiler and linker there are invoked by VS.
On your question how to configure a project for remote debugging: it's probably best to start with the Blink example in Visual Studio 2017 (File, New, Project, Installed, Visual C++, Cross Platform, Linux => Blink). It should run without problems. From there, you can build further on your project.
In the Blink example, they use wiringPiSetupSys() and the remote command gpio export 17 out to run your program without sudo. I've found that changing that to wiringPiSetup() and disabling the remote command, it still is possible to run and debug the program. On the Raspberry I can run the program from it's folder by issuing ./[programname]. If that doesn't work for you, you could run the program by issuing sudo ./[programname].
I'm a newbie in both LLVM developing and cpp.
I wanted to ask if there was a way to develop a pass for LLVM in Xcode having all the typical features available in an IDE like autocomplete and syntax code highlighting.
Right now I am just writing c++ code, checking everything I need on the documentation, but, as you can imagine, this is really slowing me down and it's really error prone...
Don't know if this can help, but my LLVM folder is structured this way:
"llvm_3.8_source/" root folder of llvm3.8 source files
"llvm_3.8_source/build" root folder of my llvm3.8 build
Thanks
Yes, it is possible.
LLVM uses CMake as a build-system generator. CMake supports such things as old good makefiles, ninja, xcode, and visual studio.
You can simply create Xcode-project using the following commands from terminal:
cd llvm_build
cmake -G Xcode path/to/llvm/sources
open LLVM.xcodeproj
First you will see lots of errors and 'red' marks. It's because some parts of LLVM sources are generated during compilation.
All files will be generated as soon as you attempt to build project first time and all the 'red' marks will gone.
You can read this article to get a bit more info on the topic:
Getting started with LLVM/Clang on OS X
I was coding a wxWidgets application many days or a week ago, and after the break returned to work today. Before the break, application built and ran successfully, but today ( without changing any code in the project ) I get this build error :
obj\Debug\appwx.o||In function `Z8wxStrdupPKc':|
C:\wxWidgets-3.0.1\include\wx\wxcrtbase.h|679|undefined reference to `wxCRT_StrdupA(char const*)'|
I am using wxWidgets 3.0.1 & CodeBlocks on a Win 7 system.
Obviously during the break I didn't touch that particular project, so the code is same. I did of course search for the solution and found this thread, as well as this thread. Reading them reminded me that I did change a compiler setting meanwhile -> -std=c++11 for gcc to follow the ISO C++11 standard.
I unchecked that option now, but the build error remains.
What do I need to change in the project so that it will build successfully again like it did the last time I was building it ?
You must recompile everything (i.e. both wxWidgets and your application) using the same compiler options and if you use configure to build wxWidgets, you also need to ensure it uses the same options as well.
I need to use Cygwin to compile C++ code for an Android project. I'm having trouble compiling even a basic "hello world" program. The console gives me this message:
/usr/lib/gcc/i686-pc-cygwin/4.3.4/../../../../i686-pc-cygwin/bin/ld: unrecognized -a option `ware'
I've googled the error and the only result I've found was an issue with one of the programs (I think it was binutils) being out of date, and was resolved when that program was updated. I downloaded the entirety of the Cygwin package at once, so I don't think that's the problem. The compiler and linker aren't communicating properly. How do I fix it without changing compilers?
I figured it out - Android doesn't support the standard C++ library. Fixed by downloading http://www.crystax.net/android/ndk-r4.php
Which basically reimplements that for Android.