0

I am writing an algorithm using opencv library on an embedded processor (NIOS 2) , in order to port the library to be compiled on nios :

1 - I removed highgui and all functions that deals with IO operations .

2 - I took the remaining files (which are many) and added them to a new eclipse project along with my main.cpp.

3 - I can compile the code and run it fine but the main problem is that the output file which will be downloaded to the embedded processor (.elf file) is too large ~20 MBs with no optimization and ~6 MBs with optimization level 3.

Are there any tips to compile only the needed files in this large project and skip other files that I don't call in my code ?

Ahmed
  • 3,398
  • 12
  • 45
  • 64
  • Have you [stripped](http://stackoverflow.com/questions/1413171/what-is-strip-gcc-application-used-for) the output? – tinman Jun 17 '12 at 10:55

1 Answers1

2

The linker already strips out things that simply can't be called, assuming you are building a normal executable binary with a main().

If you know certain files aren't used at all, then remove them from the project. Any errors that result should tell you how they actually could be called, and you need to remove the code paths that could lead there.

You might use -Os to optimize for size rather than -O3, but I don't know how much difference there is on the NIOS platform, where (unless things have changed radically) optimization for size is always essential.

Potatoswatter
  • 134,909
  • 25
  • 265
  • 421
  • Normally when I wrote the algorithm on windows (used cmake and visual studio to build .lib files from opencv src) normally linking .lib files the exe output is about ~60 KBs . Why there is that huge difference ?? – Ahmed Jun 17 '12 at 08:16
  • 1
    @Ahmed 60 KB including whatever GUI you took out? I really can't tell what's going on from the information provided. If the code is truly dead, then you can remove it (such as removing files from the project) with no issues. – Potatoswatter Jun 17 '12 at 08:18
  • yes . Including everything . Here are the two scenarios I have : - Download open cv 1 - On windows build the library files uisng visual studio and cmake from complete src of opencv . out ~60 KB 2 - On NIOS first delete some windows related files from src and then take the remaining src files , put them in a project then compile. out ~6MB – Ahmed Jun 17 '12 at 08:27
  • Optimization by size yielded ~5MBs file . So you are suggesting that I go through the files and delete any unused ones ? The problem is that those files rely on each other heavily and deleting any of them produces a linking error although I don't use most of them . – Ahmed Jun 17 '12 at 08:31
  • @Ahmed It's strange that Visual Studio would produce a small executable from exactly the same source that results in a large one from GCC. But the only solution I can suggest from the information provided is to remove what you do not use *and fix the resulting link errors*. Link errors are most often fixed by removing yet more code. Just taking out one file at a time won't be productive, remove everything you are not using (or start from nothing and add what you do use). You should also not be modifying OpenCV. – Potatoswatter Jun 17 '12 at 08:43