|
Get list of undefined symbols without actually invoking build |
Mark Oates
Member #1,146
March 2001
|
I'm using clang and from time to time I change the signature of a class, and I add or remove a new parameter/argument to the constructor or whatever. This changes the signature, which means that older obj files which have already been compiled with the previous header are expecting a signature from the previous. Naturally during compile, the error message comes out something like this: Undefined symbols for architecture x86_64: "Hexagon::System::Action::CreateThreeSplitFromComponent::CreateThreeSplitFromComponent(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, Blast::Project::Component, std::__1::vector<StageInterface*, std::__1::allocator<StageInterface*> >&, int, int, int, ALLEGRO_COLOR, ALLEGRO_COLOR)", referenced from: System::create_three_split_from_last_component_navigator_selection() in System.o ld: symbol(s) not found for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation) make[1]: *** [bin/tests/Hexagon/System/Action/CreateThreeSplitFromComponentTest] Error 1 This is fine, but I'd like to get this list of undefined references without attempting a build. Like a "dry run" if you will. I can't seem to find documentation or figure out what the keywords are to search for this topic. There's also an extra little challenge searching for this since the internet is deeply flooded with people trying to figure out "what the heck undefined references?! ". -- |
Peter Hull
Member #1,136
March 2001
|
What the heck are undefined references?
|
RmBeer2
Member #16,660
April 2017
|
sound like a try mix of 32 and 64 bits of binaries files. πππ π BlackRook WebSite (Only valid from my installer) π C/C++ π GNU/Linux π IceCream/Cornet π πππ Rm Beer for Emperor 2021! Rm Beer for Ruinous Slave Drained 2022! Rm Beer for Traveler From The Future Warning Not To Enter In 2023! Rm Beer are building a travel machine for Go Back from 2023! Rm Beer in an apocalyptic world burning hordes of Zombies in 2024! |
dthompson
Member #5,749
April 2005
|
Hmm, I imagine this'd be difficult to do without linking. There are static analysis tools out there - I think they'd pick up on that - but they normally take longer than compiling anyway ______________________________________________________ |
Peter Hull
Member #1,136
March 2001
|
It's part of C++'s model that there should be 'separate compilation' - i.e. source files are first compiled to object files and then object files are linked to produce the final output. So in your case I think there's no way clang can discover that there's a symbol reference with no matching definition until it tried to do the link. However it's something that IDEs do (I think even VSCode can put squiggles up) and I think it's done just by doing the compiling/linking (in the background while you're typing/thinking) but never writing out the files. You might be able to do it by telling the linker to output to a null file (or maybe just the temp directory) but I'm not sure what the benefit will be. [edit] also - the set up of header files and dependencies in your makefile ought to allow you to see which files need recompiling if you change a class definition.
|
Edgar Reynaldo
Major Reynaldo
May 2007
|
You can use nm to do this. Unlinked entries are marked with a U. Pass the output to grep and you have your list. My Website! | EAGLE GUI Library Demos | My Deviant Art Gallery | Spiraloid Preview | A4 FontMaker | Skyline! (Missile Defense) Eagle and Allegro 5 binaries | Older Allegro 4 and 5 binaries | Allegro 5 compile guide |
Chris Katko
Member #1,881
January 2002
|
I'm almost positive you can do a fake compile for static analysis. It just doesn't output an executable. -----sig: |
Peter Hull
Member #1,136
March 2001
|
Edgar Reynaldo said: You can use nm to do this. Unlinked entries are marked with a U. Ah, but then you'd see all undefined symbols from that object file, not just the ones that aren't going to remain undefined after linking. Chris Katko said: I'm almost positive you can do a fake compile for static analysis. It just doesn't output an executable. You could do `ld -o /dev/null ...` but not sure what the benefit is. If link fails it doesn't clobber a previous, good exe with an empty file or anything (does it?)
|
Mark Oates
Member #1,146
March 2001
|
Peter Hull said: However it's something that IDEs do (I think even VSCode can put squiggles up) and I think it's done just by doing the compiling/linking (in the background while you're typing/thinking) but never writing out the files. You might be able to do it by telling the linker to output to a null file (or maybe just the temp directory) but I'm not sure what the benefit will be. I did find this SO: https://stackoverflow.com/a/51438065/6072362 It sounds a lot like what you describe. Seems to be the best theory so far. -- |
|