Doh! Found it. It's gcc that causes the bug, not Nim, it was the **filename case**.
Nim generates lower case .c files, but in the project has files with upper case eg. 'TEST.C'. So I reanamed all .c files generated from Nim to uppercase (with .C extension) and it works!