| View previous topic :: View next topic   | 
	
	
	
		| Author | 
		Message | 
	
	
		
			allenhuffman
 
 
  Joined: 17 Jun 2019 Posts: 643 Location: Des Moines, Iowa, USA 
			
			 
			 
			
			 
			
			
			
			
			
  
		  | 
		
			
				| "File can not be opened for write" .o file open by | 
			 
			
				 Posted: Mon Jun 17, 2019 8:35 am     | 
				     | 
			 
			
				
  | 
			 
			
				I have a new PC with a fresh install of the CCS C Compiler. I am running into issues with a simple, multi-file test program. I will get a build error:
 
 
 	  | Code: | 	 		  *** Error 129 "C:(path here)\LogTest.c" Line 284(1,2): File can not be opened for write
 
C:\(path here)\LogTest.o ===>  1 Errors,  1 Warnings.
 
Build Failed. | 	  
 
 
That .o file is locked and cannot be deleted from Windows. I have to close the CCS C Compiler and reopen it, then I can build again.
 
 
Has anyone else encountered this? | 
			 
		  | 
	
	
		  | 
	
	
		
			Ttelmah
 
 
  Joined: 11 Mar 2010 Posts: 19967
  
			
			 
			 
			
			
			
			
			
			
			
  
		  | 
		
			
				 | 
			 
			
				 Posted: Mon Jun 17, 2019 10:30 am     | 
				     | 
			 
			
				
  | 
			 
			
				Almost certainly means the process does not have write permission
 
in the directory where the file is being created.
 
You don't post the path to the directory you are working in?. Remember
 
a 'user' won't have write permission in the PIC compiler directory for
 
example. Are you the working as the same user you used when
 
installing the compiler?.
 
Windows 10, has a security feature that when accessing certain folders
 
it won't actually write to these but will instead create a 'virtual' version
 
temporarily. Where is your file where you are attempting to create
 
the project?. | 
			 
		  | 
	
	
		  | 
	
	
		
			allenhuffman
 
 
  Joined: 17 Jun 2019 Posts: 643 Location: Des Moines, Iowa, USA 
			
			 
			 
			
			 
			
			
			
			
			
  
		  | 
		
			
				 | 
			 
			
				 Posted: Mon Jun 17, 2019 10:59 am     | 
				     | 
			 
			
				
  | 
			 
			
				 	  | Ttelmah wrote: | 	 		  Almost certainly means the process does not have write permission
 
in the directory where the file is being created.
 
You don't post the path to the directory you are working in?. Remember
 
a 'user' won't have write permission in the PIC compiler directory for
 
example. Are you the working as the same user you used when
 
installing the compiler?. | 	  
 
 
Same user. Files are in a folder on my Desktop.
 
 
It's the .o files, nothing else. I close the IDE, then reopen and start again. It is leaving some process open hanging on to that file. Very odd.  I've had it happen on several tiny programs I've been writing to test things. Very consistent issue.
 
 
Trying to delete the .o file from Windows shows "The action can't be completed because the file is open in C Compiler IDE."  Fun. | 
			 
		  | 
	
	
		  | 
	
	
		
			Ttelmah
 
 
  Joined: 11 Mar 2010 Posts: 19967
  
			
			 
			 
			
			
			
			
			
			
			
  
		  | 
		
			
				 | 
			 
			
				 Posted: Mon Jun 17, 2019 11:31 am     | 
				     | 
			 
			
				
  | 
			 
			
				Folder on your desktop, is an odd place to be developing.
 
This won't work, if you have ever enabled the controlled folder access in
 
Windows 10. 
 
Start Menu
 
Settings
 
Update and security
 
Windows security
 
Opem Windows Defender Security Centre
 
Protection from Virus & Threats
 
Turn off Controlled Folder access.
 
 
Key to remember is that the compiler is not 'you', and doesn't have your
 
security access.
 
 
A folder in My documents, is a more normal place to put things. | 
			 
		  | 
	
	
		  | 
	
	
		
			allenhuffman
 
 
  Joined: 17 Jun 2019 Posts: 643 Location: Des Moines, Iowa, USA 
			
			 
			 
			
			 
			
			
			
			
			
  
		  | 
		
			
				 | 
			 
			
				 Posted: Mon Jun 17, 2019 11:40 am     | 
				     | 
			 
			
				
  | 
			 
			
				 	  | Ttelmah wrote: | 	 		  Folder on your desktop, is an odd place to be developing.
 
 | 	  
 
 
I'm not   I'm just trying to get things to work. My initial thought was file permissions, so I created projects in a place I know that wouldn't be an issue  
 
 
 	  | Ttelmah wrote: | 	 		  This won't work, if you have ever enabled the controlled folder access in
 
Windows 10. 
 
Start Menu
 
Settings
 
Update and security
 
Windows security
 
Opem Windows Defender Security Centre
 
Protection from Virus & Threats
 
Turn off Controlled Folder access.
 
 
Key to remember is that the compiler is not 'you', and doesn't have your
 
security access.
 
 
A folder in My documents, is a more normal place to put things. | 	  
 
 
This isn't a permissions issue, though. It's a "something has the .o file open so I can't overwrite it" issue.
 
 
I can't even delete it from Windows Explorer (shows "in use") until I close the IDE. Then it's all fine.
 
 
Also, "Controlled folder access" is OFF on my system. | 
			 
		  | 
	
	
		  | 
	
	
		
			Ttelmah
 
 
  Joined: 11 Mar 2010 Posts: 19967
  
			
			 
			 
			
			
			
			
			
			
			
  
		  | 
		
			
				 | 
			 
			
				 Posted: Mon Jun 17, 2019 11:53 am     | 
				     | 
			 
			
				
  | 
			 
			
				Are you running the CCS IDE or another IDE like MPLAB?. Are you
 
compiling normally or trying to use linking?. The .o file is not normally
 
generated or used. Why are you using it?. | 
			 
		  | 
	
	
		  | 
	
	
		
			allenhuffman
 
 
  Joined: 17 Jun 2019 Posts: 643 Location: Des Moines, Iowa, USA 
			
			 
			 
			
			 
			
			
			
			
			
  
		  | 
		
			
				 | 
			 
			
				 Posted: Mon Jun 17, 2019 12:03 pm     | 
				     | 
			 
			
				
  | 
			 
			
				 	  | Ttelmah wrote: | 	 		  Are you running the CCS IDE or another IDE like MPLAB?. Are you
 
compiling normally or trying to use linking?. The .o file is not normally
 
generated or used. Why are you using it?. | 	  
 
 
CCS compiler, installed last week.
 
 
I am just clicking "Rebuild"  
 
 
I do not know what generates the .o or what its purpose is. My team lead has me go into project Options and enable all the items in the "List File" section, but everything else is left at defaults. (Though I have now started making an output directory and setting that in the options.) | 
			 
		  | 
	
	
		  | 
	
	
		
			Ttelmah
 
 
  Joined: 11 Mar 2010 Posts: 19967
  
			
			 
			 
			
			
			
			
			
			
			
  
		  | 
		
			
				 | 
			 
			
				 Posted: Mon Jun 17, 2019 1:29 pm     | 
				     | 
			 
			
				
  | 
			 
			
				Are you using #import or #export?.
 
Post a basic small program that displays the problem.
 
Also in the first window of the IDE options. I hope you have not ticked the
 
option 'Multiple Compilation Units'. If this is ticked and the code is not
 
setup to use multiple compilation units, this will cause this error.
 
 
 
Reading other threads, you seem to be trying to use the compiler in a very 
 
complex way. 
 
 
Standard way. One main file.
 
Start with processor include.
 
Then fuses
 
Then clock statement
 
Then any setup for things like serial, SPI etc.
 
 
Then include the other files forming the project.
 
 
Then any more code that is needed.
 
 
Compile this. No linking, multiple compilation units etc.
 
 
Multiple compilation units should _only_ be used by somebody who 
 
understands how to do this, and the 'downsides' of this (It makes 
 
optimsation much less efficient).
 
 
In MPLAB, simply make the 'main' file above the only 'source file'. Add
 
all other code files to the 'header files' section. | 
			 
		  | 
	
	
		  | 
	
	
		
			allenhuffman
 
 
  Joined: 17 Jun 2019 Posts: 643 Location: Des Moines, Iowa, USA 
			
			 
			 
			
			 
			
			
			
			
			
  
		  | 
		
			
				 | 
			 
			
				 Posted: Tue Jun 18, 2019 8:17 am     | 
				     | 
			 
			
				
  | 
			 
			
				 	  | Ttelmah wrote: | 	 		  Are you using #import or #export?.
 
Post a basic small program that displays the problem.
 
Also in the first window of the IDE options. I hope you have not ticked the
 
option 'Multiple Compilation Units'. If this is ticked and the code is not
 
setup to use multiple compilation units, this will cause this error.
 
 | 	  
 
 
We use the CCS PIC C Compiler setup, and Multiple Compiler Units. We have a number of projects for various boards using different PIC24 processors. The project I will be moving my code into uses 16 files (so it's pretty tiny).
 
 
What has to be set up special for multiple compile files? I did not notice anything that stood out in the various projects I have here.
 
 
For instance, something like this:
 
 
 	  | Code: | 	 		  
 
main.c
 
-----
 
#include <SampleProject.h>
 
 
void main()
 
{
 
   int result;
 
 
   result = AddTwoNumbers( 10, 30 );
 
}
 
 
AddTwoNumbers.c
 
-----
 
#include <SampleProject.h>
 
 
int AddTwoNumbers( int Number1, Number 2 )
 
{
 
   return ( Number1 + Number 2);
 
}
 
 | 	  
 
 
My test code is real generic -- nothing hardware specific, just basic code. Sometimes it builds fine, sometimes is gives me errors or leaves a .o open and can't overwrite it.
 
 
From reading other threads here, I have learned there are just "quirks" (or bugs) in the IDE and there are many workarounds. Someone pointed me to "#use DYNAMIC_MEMORY" for an error I was seeing. Even though I am not using malloc(), etc. I included that, and the linker issue went away. I just need to learn the quirks  
 
 
Thanks for your response! | 
			 
		  | 
	
	
		  | 
	
	
		
			Ttelmah
 
 
  Joined: 11 Mar 2010 Posts: 19967
  
			
			 
			 
			
			
			
			
			
			
			
  
		  | 
		
			
				 | 
			 
			
				 Posted: Tue Jun 18, 2019 10:52 am     | 
				     | 
			 
			
				
  | 
			 
			
				The problem is you are setting the compiler to use multiple compilation
 
units, but your code does not use MCU's. Result there is no .o file to use.
 
For a project to use MCU's, there has to be an export and import, and 
 
at least two modules generated.
 
Understand using MCU's, is generally a very 'bad' way to use CCS.
 
It generates more efficient code when allowed to compile as a single 
 
program not using MCU's. It really is not the way to work. | 
			 
		  | 
	
	
		  | 
	
	
		
			allenhuffman
 
 
  Joined: 17 Jun 2019 Posts: 643 Location: Des Moines, Iowa, USA 
			
			 
			 
			
			 
			
			
			
			
			
  
		  | 
		
			
				 | 
			 
			
				 Posted: Tue Jun 18, 2019 11:09 am     | 
				     | 
			 
			
				
  | 
			 
			
				 	  | Ttelmah wrote: | 	 		  The problem is you are setting the compiler to use multiple compilation
 
units, but your code does not use MCU's. Result there is no .o file to use.
 
For a project to use MCU's, there has to be an export and import, and 
 
at least two modules generated.
 
Understand using MCU's, is generally a very 'bad' way to use CCS.
 
It generates more efficient code when allowed to compile as a single 
 
program not using MCU's. It really is not the way to work. | 	  
 
 
Well, it's definitely making .o files. I'll dig into it. As to using MCU or not, I won't have a choice    That's just how all the projects at my job are.
 
 
Thanks! | 
			 
		  | 
	
	
		  | 
	
	
		 |