0

This is a problem I am seeing running emacs v26.1 on Windows 7, but the problem does not appear to be present when running on ubuntu.

Code below:

#include <iostream>
#include <string>

using std::cout;
using std::endl;
using std::cin;
using std::string;

string getName() {
  string name; 
  cin >> name;
  return name;
}

void PromptForName() {
  cout << "What is your name? ";
}

int main() {
  PromptForName();
  cout << "Hello " << getName() << ", nice to meet you!\n";
}

Debugging code like this:

g++ -g hello.cpp -o hello.exe

to debug in emacs:
m-x gdb
m-x gdb-many-windows

(gdb) run
What is your name? Starting program: d:\projects\chunks\programming\saying-hello\c++\hello.exe 
[New Thread 16540.0x10b0]
Angus
Hello -interpreter-exec, nice to meet you!
[Inferior 1 (process 16540) exited normally]

Why do I get :

Hello -interpreter-exec, nice to meet you!

And not

Hello Angus, nice to meet you!

which is what I would expect. It works fine if I run on ubuntu v16.04.6 LTS and emacs v24.5.1, gcc version 5.4.0 20160609 (Ubuntu 5.4.0-6ubuntu1~16.04.12).

Version info on non working Windows 7: windows 7 Professional 64 bit, Service Pack 1.

GNU Emacs 26.1 (build 1, i686-w64-mingw32)

g++ -v
gcc version 6.1.0 (GCC)

$ g++ -v
Using built-in specs.
COLLECT_GCC=C:\MinGW\bin\g++.exe
COLLECT_LTO_WRAPPER=c:/mingw/bin/../libexec/gcc/x86_64-w64-mingw32/6.1.0/lto-wrapper.exe
Target: x86_64-w64-mingw32
Configured with: ../src/configure --with-gmp=/c/temp/gcc/gmp --with-mpfr=/c/temp/gcc/mpfr --with-mpc=/c/temp/gcc/mpc --enable-languages=c,c++ --build=x86_64-w64-mingw32 --host=x86_64-w64-mingw32 --target=x86_64-w64-mingw32 --disable-multilib --prefix=/c/temp/gcc/dest --with-sysroot=/c/temp/gcc/dest --disable-libstdcxx-pch --disable-nls --disable-shared --disable-win32-registry --enable-checking=release --with-tune=haswell
Thread model: win32
gcc version 6.1.0 (GCC)

Is this likely to be a gdb or emacs problem?

session example, show args below.

Current directory is d:/projects/chunks/programming/saying-hello/c++/
GNU gdb (GDB) 7.11
Copyright (C) 2016 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-w64-mingw32".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from hello.exe...done.
(gdb) show args
Argument list to give program being debugged when it is started is "".
Breakpoint 1 at 0x401639: file hello.cpp, line 21.
(gdb) run
Starting program: d:\projects\chunks\programming\saying-hello\c++\hello.exe 
[New Thread 10464.0x2988]
warning: Can not parse XML library list; XML support was disabled at compile time

Breakpoint 1, main () at hello.cpp:21
21    cout << "Hello " << getName() << ", nice to meet you!\n";
(gdb) show args
Argument list to give program being debugged when it is started is "".
(gdb) c
What is your name? Continuing.
Angus
Hello -interpreter-exec, nice to meet you!
[Inferior 1 (process 10464) exited normally]
(gdb) n
The program is not being run.
(gdb) 
  • What does the gdb command "show args" tell you? The arguments that gdb uses when running the program could come from the command line that Emacs uses to start gdb, or from a .gdbinit file. – db48x Jul 8 at 9:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.