Bug 366039 - CDT builder tries to link a removed C file
Summary: CDT builder tries to link a removed C file
Status: NEW
Alias: None
Product: CDT
Classification: Tools
Component: cdt-build-managed (show other bugs)
Version: 8.1.0   Edit
Hardware: PC Windows 7
: P3 normal with 2 votes (vote)
Target Milestone: ---   Edit
Assignee: Project Inbox CLA
QA Contact: Jonah Graham CLA
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-12-08 09:12 EST by Missing name CLA
Modified: 2020-09-04 15:20 EDT (History)
4 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
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