4

After compiling codes in Ubuntu 12.04.3 for a while, I decided to give coding in Windows a go and installed MinGW. After the installation I set my path variables and the gcc seemed to work. However, some codes(especially those including multiple files) cannot be compiled with the same command used on Ubuntu and various error messages are displayed in the MinGW shell. Is this the expected behavior or am I doing something wrong? I appreciate your assistance.

P.S: Displayed error message

 QROMO.C: In function 'float qromo(float (*)(float), float, float, float (*)(float (*)(float), float, float, int))':
QROMO.C:24:43: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]
  nrerror("Too many steps in routing qromo");
                                           ^
C:\Users\dell\AppData\Local\Temp\ccUdzH1p.o:Q2.c:(.text+0xd5): undefined reference to `midexp'
C:\Users\dell\AppData\Local\Temp\ccUdzH1p.o:Q2.c:(.text+0xf3): undefined reference to `qromo'
C:\Users\dell\AppData\Local\Temp\ccUdzH1p.o:Q2.c:(.text+0x115): undefined reference to `qgaus'
c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../../mingw32/bin/ld.exe: C:\Users\dell\AppData\Local\Temp\ccUdzH1p.o: bad reloc address 0x20 in section `.eh_frame'
c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../../mingw32/bin/ld.exe: final link failed: Invalid operation
collect2.exe: error: ld returned 1 exit status

Edit: The errors seem to be related with QROMO.c and POLINT.c during compilation stage. The received error messages are as follows:

POLINT.C: In function 'void polint(float*, float*, int, float, float*, float*)':
POLINT.C:28:62: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]
    if ( (den=ho-hp) == 0.0) nrerror("Error in routine polint");
                                                              ^


QROMO.C: In function 'float qromo(float (*)(float), float, float, float (*)(float (*)(float), float, float, int))':
QROMO.C:24:43: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]
  nrerror("Too many steps in routing qromo");
                                           ^
rubenvb
  • 74,642
  • 33
  • 187
  • 332
Vesnog
  • 773
  • 2
  • 16
  • 33
  • 2
    Please either figure out how to copy text from a cmd.exe window (yes, it is possible, yes it is a pain) or redirect output using `> log.txt 2>&1` and post that to Stackoverflow. You can still update your question to do so. – rubenvb Jan 15 '14 at 15:53
  • @rubenvb It is not even a pain if you do it correctly, so that cannot be used as an excuse. – glglgl Jan 15 '14 at 16:07
  • @glglgl it is a pain, because lines are cut where they are cut in the cmd window, not where there is a newline. – rubenvb Jan 15 '14 at 16:11
  • @rubenvb Oh yes, that's right, alas. I wonder why they create such unusable stuff... Nevertheless, it is duable and thus doesn't qualify as excuse nevertheless. – glglgl Jan 15 '14 at 16:19
  • I redirected the output to a file as indicated and did the copy paste operation from there. I would also like to know why that command required two >'s if possible. – Vesnog Jan 15 '14 at 16:23
  • @glglgl Okay I have did as told but the error pertains to the compilation stage, can you make a suggestion? – Vesnog Jan 15 '14 at 16:41
  • @Vesnog This is not a forum, please don't add [Solved] to the title. Instead, as you already did, clicking the green checkmark will have the intended effect (plus 15 rep for the answer `;-)`) – rubenvb Jan 15 '14 at 19:53

2 Answers2

3

Since you're getting the error:

warning: deprecated conversion from string constant to 'char*'

I guess you're compiling using C++ compiler as the C++11 deprecating conversion from string constant to 'char*'.

§ C.1.1
char* p = "abc"; // valid in C, invalid in C++

You cannot get this error if you're compiling with a C compiler as this conversion still valid in C.

Compiling with a C++ compiler can generate many errors if your program is not C++ compatible.

So just make sure to compile using a C compiler.

rullof
  • 7,124
  • 6
  • 27
  • 36
  • Thanks for the answer. Does GCC interpret the files as C++ when the extensions are supplied in upper case? In addition is it possible to select the compilation mode explicitly by providing a flag? – Vesnog Jan 15 '14 at 17:54
  • 1
    @Vesnog I think that's the issue. Try to change the extensions to lower-case and try again. And try compiling with `gcc -std=gnu11 -Wall ...` – rullof Jan 15 '14 at 17:59
  • @Vesnog If you want to force gcc to compile your files as a C program check this http://stackoverflow.com/a/4216290/2727656 – rullof Jan 15 '14 at 18:08
  • When I used the option -std=gnu11 I noticed that it tries to compile the files as C++ although they are plain C. I also noticed that the file extension were upper-case and I replaced these extensions with lower-case c's and the solution was solved. – Vesnog Jan 15 '14 at 18:27
  • For information on how GCC uses filename extensions to infer how it should treat a file see http://gcc.gnu.org/onlinedocs/gcc-4.8.2/gcc/Overall-Options.html#Overall-Options – Michael Burr Jan 15 '14 at 19:59
2

The important part is the errors at the bottom:

Q2.c(...): undefined reference to `midexp'
Q2.c(...): undefined reference to `qromo'
Q2.c(...): undefined reference to `qgaus'
...
...ld.exe: final link failed: Invalid operation
...

This means you have undefined references, and is nothing specific to MinGW or Windows 7.

I'm assuming though, that these are defined in their respective source files which are included in a seemingly correct order on your compile/link line. I would suggest splitting the compile and link steps, and see where it goes wrong. This will turn the now temporar object files with randomly generated names into object files you know because you created them. You can use nm to inspect object files and see if everything is as it should be.

rubenvb
  • 74,642
  • 33
  • 187
  • 332
  • Since I am coming from Linux I have never done the compilation and linking steps separately but I am sure that the indicated GCC command works flawlessly in Ubuntu. – Vesnog Jan 15 '14 at 16:20
  • @Vesnog Coming from Linux is no reason to not do as I said in my answer. It will track down the issue at hand. – rubenvb Jan 15 '14 at 16:22
  • It turns out that there is an error in the compilation of the file QROMO.c. – Vesnog Jan 15 '14 at 16:32
  • @rubenvb I think the important part was the conversion warning :) – rullof Jan 15 '14 at 19:28
  • rullof: that I would not have guessed. Name mangling. I need to clean my crystal ball `;-)` – rubenvb Jan 15 '14 at 19:51