Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » Get list of undefined symbols without actually invoking build

This thread is locked; no one can reply to it. rss feed Print
Get list of undefined symbols without actually invoking build
Mark Oates
Member #1,146
March 2001
avatar

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?! >:(".

--
Visit CLUBCATT.com for cat shirts, cat mugs, puzzles, art and more <-- coupon code ALLEGRO4LIFE at checkout and get $3 off any order of 3 or more items!

AllegroFlare β€’ AllegroFlare Docs β€’ AllegroFlare GitHub

Peter Hull
Member #1,136
March 2001

What the heck are undefined references?

RmBeer2
Member #16,660
April 2017
avatar

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
avatar

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 :P

______________________________________________________
Website. It was freakdesign.bafsoft.net.
This isn't a game!

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
avatar

Chris Katko
Member #1,881
January 2002
avatar

I'm almost positive you can do a fake compile for static analysis. It just doesn't output an executable.

-----sig:
β€œPrograms should be written for people to read, and only incidentally for machines to execute.” - Structure and Interpretation of Computer Programs
"Political Correctness is fascism disguised as manners" --George Carlin

Peter Hull
Member #1,136
March 2001

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.

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
avatar

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.

--
Visit CLUBCATT.com for cat shirts, cat mugs, puzzles, art and more <-- coupon code ALLEGRO4LIFE at checkout and get $3 off any order of 3 or more items!

AllegroFlare β€’ AllegroFlare Docs β€’ AllegroFlare GitHub

Go to: