I'm trying to learn wxWidgets using this tutorial. It directs me to use a function called wxPuts() to put text in the console. My program compiles fine, but nothing shows up. I've searched for documentation to see exactly what wxPuts() is supposed to do so that I can get the settings right, but I'm having no luck.
Here is my code:
#include <cstdlib>
#include <wx\string.h>
int main()
{
wxPuts(wxT("A wxWidgets console application."));
return EXIT_SUCCESS;
}
What is wxPuts() supposed to do? I'm using Code::Blocks, but I also have Eclipse CDT and Microsoft Visual C++. How do I set up my IDE, so that wxPuts() gives the correct output?
I had to # include <wx/crt.h>
to get wxPuts to work using Code Blocks 17.12, wxWidgets 3.1.2 on Windows 7 Pro.
I received the advice to include crt.h from:
Why doesn't Clion recognise WxPuts?
Hope this helps someone else.
I feel kinda dumb. It turns out I wasn't waiting long enough for the text to pop up. For some reason it takes a very long time. My bad.
This function of wx/string.h library. It's show message in console. In order to work correctly. This should include some additional information in project properties.
Right Click to Project Properties
Built -> C++ Compiler -> in Additional Options add "wx-config --cxxflags" without quotes
Built -> Linker -> in Additional Options add "wx-config --libs" without quotes
Then it should works fine.
Related
I'm trying to switch from JetBrains CLion to VS Code. When I was trying some code that worked in CLion perfectly, I ran into troubles. I was trying to open only a basic coroutine implementation.
Line:
#include <coroutine>
is good, without errors, but when I try something like:
std::suspend_always initial_suspend()...
or:
co_await std::suspend_never() {}
VS Code shows problems that "namespace std contains no member suspend_always", etc.
Like I said- the only thing I did was that I opened the same code, that worked in CLion.
The first thing I tried was checking paths to compiler (mingw gcc) - the same as in CLion.
Then I tried to add the line
using namespace std;
, but it helped only on one line. I don't get it.
I tried also change standard in cpp_properties.json file to "C++20".
Nothing on google helped me, but maybe I just donĀ“t know what to search for.
I am trying to work with Emscripten. I have the compiler set up and working and now I'd like to write some code.
However, the include for emscripten remains underlined in red and I can see this error:
#include <emscripten/emscripten.h>
#include errors detected. Please update your includePath. Squiggles are disabled for this translation unit (D:\MYPROJECT\cpp\main.cpp).C/C++(1696)
cannot open source file "emscripten/emscripten.h"C/C++(1696)
A "Quick fix" (quotes intended) takes me to the Microsoft C/C++ Extension - IntelliSense Configurations. And there I can edit include paths. I have created a new configuration named EMSCRIPTEN and set these paths:
${workspaceFolder}/cpp/**
D:\lib\emsdk\upstream\emscripten\system\include
But this has no effect. Now if I do add this to the default configuration that was there from the start (Win32), it works. But I don't want to use that one for my emscripten project! I was kinda hoping to convince to IDE to compile my programs as well.
So how do I set per-workspace C++ compiler settings to a given configuration?
Ok, I found it, it's to the right bottom of the screen next to language type selection:
I'm fairly new to Xcode and have recently gotten an error message that is probably clear to anyone who knows what they're doing, but I am unsure how to react to this one.
I have a project that is mostly C++, with just a few C files in it. Everything was fine until I tried to add some code to find the computer's MAC address. Apple provides a project example (GetPrimaryMACAddress), and I downloaded, built, and tested that. It works just fine.
After that, I simply copied the C source from the Apple example project and included it into my code project. Then I started getting this error message:
I have tried including the IOKit framework explicitly via the linker; no help. I tried adding more #include statement to the Apple example code; no help. I think that I do not understand what the compiler message is telling me regarding importing from module 'Darwin.MacTypes'.
Clicking on the error message took me to a line in usr/include/MacTypes.h:
I'm not clear on how to Import Darwin.MacTypes. I don't really understand how the source code for GetMACAddress could compile so effortlessly in one project and not another. I didn't rearrange nor add nor delete any of the #include statements in the Apple-supplied C file.
I'll bet there is a simple answer that I am just not seeing. How should I react to this error message?
I had a similar problem with types like UInt16 and UInt32. I just included the MacTypes with the following include statement:
#include <MacTypes.h>
This solved all my type-problems for my example c-file.
Let me guess, when you want to compile C++ source, you should create a C++ source file
(On the toolbar: File > New > File.. > Source > C++ File)
My program compiles fine, but Netbeans tells me "Unable to resolve identifier to_string."
I tried everything in "Netbeans 7.2 shows "Unable to resolve identifier" , although build is successful" and I set the "C++ standard" to "C++11" in the code assistance options.
This is the only function giving this problem so far. It is however also the first C++11 feature I am using, which leads me to believe it has something to do with Netbeans not understanding that I am using C++11, although I specify it explicitly in the code assistance menu.
Minimal example:
#include <string>
int main() {
std::to_string(1);
}
EDIT: the same problem arises where using nullptr
EDIT2: I suddenly realized it might be important to mention that I do not use a generated Makefile, but SCons.
I know this question is seven months old but since it came up as the second result to a google search I'll tell the answer I came up with. For Netbeans at least. Go to your project properties and make sure you have you "C Compiler"->"C Standard" set to C11, and your "C++ compiler"->"C++ Standard" set to C++11. You have to set BOTH or it will still give false errors!
This will solve the problem:
Right click on "Project".
Select "Code Assistance".
Clean C/C++ cache.
Restart IDE.
Autocomplete and sometimes even syntax highlighting are always faulty with C++. The more you go in depth with C++ and C++11, the more Eclipse and Netbeans will start underlining everything with a red wavy line. Some of my (correct and perfectly compiling) programs are a huge red wavy line. I suggest you disable error markers altogether and you keep autocomplete, but in many cases it just won't work and you have to make the best of it.
I had the same situation. This was occurred because I used .c file instead of .cpp
for Netbeans 8.2 (on Linux) only the following worked for me: Tools -> Options -> Code Assistance -> Macro Definitions:
change:__cplusplus=199711L
to:__cplusplus=201402L
for C++14
or to __cplusplus=201103L
for C++11
I did all the above but what did the trick for me was recognizing that the Makefile had g++ rather than g++ -std=c++11.
To resolve c++17 related 'Unable to resolve identifier' in latest netbeans 8.2 or 9 version, one may need to set the macro definition __cplusplus=201703L as the default C++14 standard macro definition unable to resolve those unexpected error messages appeared in the editor.
How can my program compile successfully but eclipse shows me "Semantic Errors" and how could I get rid of those errors?
The error messages I have are the following
Method 'c_str' could not be resolved (this happens also for compare and size on strings)
Here an example:
std::string someotherstring = "test";
std::string name = someotherstring.c_str();
The problem here is that it also creates follow up errors which seem all to be not true, my software compiles and runs as intended and even uses the "c_str()" returns to process messages. It seems only to be a display issue in Eclipse.
I have searched now for hours, tried to use a custom indexer but for some reason it won't go away. Maybe someone else has a good idea what to do here as Google spits out nothing about this specific problem. (I have even tried to use different C++11 standard flags as I thought it might had an impact)
I had the same problem. Solved by simply run a index -> rebuild. You can find that by clicking on the project main folder with the right button.
Cheers
If you're building your projects using mingw and using C++11, you can not use the default dialect option of -std=c++0x.
Click on 'GCC C++ Compiler' and in the Command: textbox, enter -std=gnu++0x after the g++