Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 366039

Summary: CDT builder tries to link a removed C file
Product: [Tools] CDT Reporter: Missing name <arthur.gauthier>
Component: cdt-build-managedAssignee: Project Inbox <cdt-build-managed-inbox>
Status: NEW --- QA Contact: Jonah Graham <jonah>
Severity: normal    
Priority: P3 CC: cdtdoug, john, malaperle, piotr.aniola
Version: 8.1.0   
Target Milestone: ---   
Hardware: PC   
OS: Windows 7   
See Also: https://git.eclipse.org/r/58908
https://git.eclipse.org/c/cdt/org.eclipse.cdt.git/commit/?id=e62e2772fe26628dbdc0cf86675983f7c399e7aa
https://git.eclipse.org/r/62635
https://git.eclipse.org/c/cdt/org.eclipse.cdt.git/commit/?id=e37153ae8c4c43cd54d657cc2e8ea3ccb18548a2
Whiteboard:

Description Missing name CLA 2011-12-08 09:12:24 EST
Build Identifier: M20110909-1335

In a standard C/C++ project (for instance: the basic hello world project), if you remove a C file from a source folder. Internal builder Linker will try to link object file corresponding to the removed file.
The test has been done with CDT 7.0 and CDT 8.0 and it is the same.
It seems that removedCalcVisit() in BuildDescriptor.java adds the removed C/C++ file to list of files to compile.

The only solution is to clean project and compile everything once again. (waste of time with hundreds of C files).

Reproducible: Always

Steps to Reproduce:
1.Create a Hello World C++ Project.
2.Build project (exe is geenrated).
3.Copy/Past the C file to create a copy with a different name.
4.Delete the original C file.
5.try to build again
-> Linker fails with message:

**** Internal Builder is used for build               ****
g++ -O0 -g3 -Wall -c -fmessage-length=0 -o src\Copy of <orignal>.o ..\src\Copy of <orignal>.cpp
g++ -o visual.exe src\Copy of <orignal>.o src\<orignal>.o
src\<orignal>.o: In function `main':
<orignal>.cpp:12: multiple definition of `main'
src\Copy of <orignal>.o: /Copy of <orignal>.cpp:12: first defined here
collect2: ld returned 1 exit status
Build error occurred, build is stopped
Time consumed: 1070  ms.
Comment 1 Piotr Aniola CLA 2012-12-11 10:40:55 EST
I am unable to reproduce this on master. My Build output is:

16:39:47 **** Incremental Build of configuration Debug for project test366039 ****
make all 
Building file: ../src/test366039_2.c
Invoking: Cygwin C Compiler
gcc -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"src/test366039_2.d" -MT"src/test366039_2.d" -o "src/test366039_2.o" "../src/test366039_2.c"
cygwin warning:
  MS-DOS style path detected: C:\eclipse-SDK-4.2-win32\eclipse\runtime-New_configuration\test366039\Debug
  Preferred POSIX equivalent is: /cygdrive/c/eclipse-SDK-4.2-win32/eclipse/runtime-New_configuration/test366039/Debug
  CYGWIN environment variable option "nodosfilewarning" turns off this warning.
  Consult the user's guide for more details about POSIX paths:
    http://cygwin.com/cygwin-ug-net/using.html#using-pathnames
Finished building: ../src/test366039_2.c
 
Building target: test366039.exe
Invoking: Cygwin C Linker
gcc  -o "test366039.exe"  ./src/test366039_2.o   
Finished building target: test366039.exe
Comment 2 John Dallaway CLA 2015-10-26 06:32:15 EDT
NOTE: This bug is observed with the CDT "Internal Builder" only.

The reported issue is due to incorrect handling of BuildStep objects by the RebuildStateSynchronizer in the case where the number of input resources has decreased since the previous build but remains greater than zero.

There is a related issue that the obsolete input resources (eg object files) are not removed from the project.

Patch to follow.
Comment 3 Eclipse Genie CLA 2015-10-26 07:05:48 EDT
New Gerrit change created: https://git.eclipse.org/r/58908
Comment 4 John Dallaway CLA 2015-10-26 07:19:53 EDT
This patch updates the set of input resources associated with a build step when the RebuildStateSynchronizer has determined that an input resource has been removed. It also deletes the underlying file resource to avoid cluttering the project with obsolete generated files.

The resulting behaviour of the "Internal Builder" mirrors that of the "External Builder" on the first build following a source file deletion.

Without this patch, object code may remain in the build artifact after the originating source file has been deleted and the project built.
Comment 6 Eclipse Genie CLA 2015-12-14 10:31:24 EST
New Gerrit change created: https://git.eclipse.org/r/62635