Author Topic: Strange compiling behavior  (Read 6331 times)

Coywolf

  • Guest
Strange compiling behavior
« on: November 02, 2009, 08:12:39 am »
Hello, I've noticed something strange with compiling a project of mine. I don't know if this has anything to do with the compiler or with code blocks. Basically, I've noticed that I'm getting different compile results depending on where my file is located. Originally, I had my project buried somewhere in Documents. It gave errors there. But for various tests I was doing, I decided to make a copy. I just saved it on the Desktop. Once I tried compiling there, it compiled fine. All the errors say
Code
error: invalid conversion from `void*' to `int*'
for every time I had a line like
Code
int *setA = malloc(1000);
The files are EXACTLY the same in both places. In fact, continuing to test, I started doing a save as in each folder on the way to its original location of
Code
C:\Users\****\Documents\CS 240\project 3\project 3\project3.c
It started giving those errors when I got to CS 240. So basically I'm wondering if this is a compiler error or a code blocks error, and if anyone knows how to fix it. Or even if I should be getting those errors or if it should actually be ignoring them.
I'm running code blocks 8.02, just the normal download, not nightly. 64-bit Vista. I got this with the standard C compiler, though I also tried downloading MinGW 5.1.6 and got the same behavior.

EDIT: realized I posted the results backwards. I was getting errors when it was in Documents, and not getting them on the Desktop. I updated the post
« Last Edit: November 02, 2009, 08:19:25 am by Coywolf »

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: Strange compiling behavior
« Reply #1 on: November 02, 2009, 09:22:35 am »
Please search the forum before you ask...
The compiler in the 8.02 release does not work on Vista!
Also some compilers have problems with spaces in paths... :?

Devs/site admins: can you add a message to the main page/download page that the compiler is broken on vista?
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

zabzonk

  • Guest
Re: Strange compiling behavior
« Reply #2 on: November 02, 2009, 09:48:06 am »
Also, check that you are compiling your source files as C and not C++. C++ does not provide an implicit cast from void * to other pointer types.

Coywolf

  • Guest
Re: Strange compiling behavior
« Reply #3 on: November 02, 2009, 08:14:02 pm »
I read the forums and saw things saying the compiler didnt work, which is why I tried downloading another, but continued to get the same behavior.

How do I check how its compiling? I just click the build button, I don't know if its compiling as C or C++

I guessed the spaces thing mightve been the problem, but it doesnt seem to make sense that it would either give errors or not. It would seem to me like it should be unable to run the compiler at all due to the file path

zabzonk

  • Guest
Re: Strange compiling behavior
« Reply #4 on: November 02, 2009, 08:30:14 pm »
Firstly, check that you really know which compiler you are using. To do this go to the Settings menu and select Compiler & Debugger. Then in the dialog that pops up, select Toolchain Executables and check that the directory it refers to is the one of the latest MinGW you say you installed, and not the one that came with the original CB installation. If it isn't change it so that it is and try doing a complete rebuild of your project (select Rebuild from Build menu)

If this still fails, please post here the command that gets executed by Code::Blocks, using copy and paste from the CB Build Log tab.

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: Strange compiling behavior
« Reply #5 on: November 02, 2009, 09:18:15 pm »
Try: http://wiki.codeblocks.org/index.php?title=FAQ#Q:_How_do_I_troubleshoot_an_compiler_problem.3F
The compiler executable should be gcc, if it is g++ you are compiling it as c++, not c.
If that is the case in the project manager -> right click your c file -> properties -> advanced -> verify that there is C no CPP

If you can't understand why it doesn't work, paste the output here.

(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Coywolf

  • Guest
Re: Strange compiling behavior
« Reply #6 on: November 03, 2009, 08:29:53 am »
I've made sure that I changed the compiler to point to the new directory.

So here is what the build log says when I compile. The one that gives errors is in fact running g++.
Code
mingw32-g++.exe    -c "C:\Users\Mike\Documents\CS 240\project3\project3\project3.c" -o "C:\Users\Mike\Documents\CS 240\project3\project3\project3.o"
C:\Users\Mike\Documents\CS 240\project3\project3\project3.c: In function `int main()':
Errors....
and for the copy not giving errors. Side question - should this be running g++ also? I notice it does gcc, then g++ on the .o. It seems like this is just to make an .exe. Is that the case?
Code
mingw32-gcc.exe    -c C:\Users\Mike\Desktop\project3.c -o C:\Users\Mike\Desktop\project3.o
mingw32-g++.exe  -o C:\Users\Mike\Desktop\project3.exe C:\Users\Mike\Desktop\project3.o  
Process terminated with status 0 (0 minutes, 0 seconds)
0 errors, 0 warnings
I looked in the properties for each file, and under the advanced tab, there is nothing. The fields are grayed out and the drop down box under 'Custom Build' is empty

EDIT:
ok, what I said about the properties was when the files were just by themselves. When I opened the project3.c file with the project I set up for it, I had a different screen. The compiler variable is CC only. Looking at the build output, its running gcc. So I suppose I should keep things in project files. Is there a reason it would be running the g++ when the file is just by itself? I can only assume that having spaces in the path is invalid for gcc, so it choose g++ instead.
« Last Edit: November 03, 2009, 08:34:46 am by Coywolf »

Offline Jenna

  • Administrator
  • Lives here!
  • *****
  • Posts: 7255
Re: Strange compiling behavior
« Reply #7 on: November 03, 2009, 10:49:53 am »
This seems to be a bug in C::B.
The c-file in quotes (it's quoted because of the spaces included) is not recognized as c-file, but as c++-file, if it is not in a project.

And you wrote, that the content of the advanced tab is inactive, so I guess you use the files without a project.

Offline thomas

  • Administrator
  • Lives here!
  • *****
  • Posts: 3979
Re: Strange compiling behavior
« Reply #8 on: November 03, 2009, 12:57:30 pm »
Yes, looks that way, I'm getting the same behaviour when trying to compile C without a project (which admittedly was the first time ever).
"We should forget about small efficiencies, say about 97% of the time: Premature quotation is the root of public humiliation."

Offline Jenna

  • Administrator
  • Lives here!
  • *****
  • Posts: 7255
Re: Strange compiling behavior
« Reply #9 on: November 03, 2009, 01:24:00 pm »
Fixed in trunk (svn r5895),  debugger- (svn r5896) and scintilla-testbranch (svn r5897).

Offline thomas

  • Administrator
  • Lives here!
  • *****
  • Posts: 3979
Re: Strange compiling behavior
« Reply #10 on: November 03, 2009, 01:27:11 pm »
Too fast for me...
"We should forget about small efficiencies, say about 97% of the time: Premature quotation is the root of public humiliation."

Coywolf

  • Guest
Re: Strange compiling behavior
« Reply #11 on: November 03, 2009, 02:47:46 pm »
Hmm. Well thanks a lot for the help. Guess I'll just stick to using projects now, haha.

Offline Jenna

  • Administrator
  • Lives here!
  • *****
  • Posts: 7255
Re: Strange compiling behavior
« Reply #12 on: November 03, 2009, 03:03:42 pm »
Hmm. Well thanks a lot for the help. Guess I'll just stick to using projects now, haha.
As workaround you can also use a path with no spaces or wait for the next nightly.