Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VERSION file causes an error when building software that includes <version> and searches libpcap source directory for headers with a case-insensitive file system #1331

Open
KrawMire opened this issue Jul 6, 2024 · 17 comments

Comments

@KrawMire
Copy link

KrawMire commented Jul 6, 2024

I suppose this error only happens on MacOS. When I use libpcap in my project and link it and try to compile it using CMake, it fails with error:

lib/third_party/libpcap/version:1:1: error: expected unqualified-id

As I understood, MacOS compiler is trying to use this file as simple code file because the problem is caused by this:

/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.5.sdk/usr/include/c++/v1/iostream:38:.

Also, I can say that this could be fixed by renaming VERSION file to VERSION.txt and changing line 552 in CMakeLists.txt from this:

file(STRINGS ${pcap_SOURCE_DIR}/VERSION

to this

file(STRINGS ${pcap_SOURCE_DIR}/VERSION.txt

@guyharris
Copy link
Member

It does not happen when building libpcap by itself with CMake, using the Ninja generator and the Ninja build tool. Perhaps there's something in the way you're including it. What generator are you using? Make, Ninja, or Xcode?

@KrawMire
Copy link
Author

KrawMire commented Jul 7, 2024

It does not happen when building libpcap by itself with CMake, using the Ninja generator and the Ninja build tool. Perhaps there's something in the way you're including it. What generator are you using? Make, Ninja, or Xcode?

Thanks for advice! I am using Ninja, so I will check my CMakeLists again

@KrawMire
Copy link
Author

KrawMire commented Jul 7, 2024

As I understood, it is a common bug for case-insensitive OS. Compiler tries to find version header file and takes VERSION. If you change VERSION file to VERSION.txt or something else, it will search this header file in another place.

For example, I found such discussions:
nmap/nmap#2747
https://groups.google.com/g/tesseract-ocr/c/MpCZe5wRYQE

So, the only workaround is to rename this file if you use case-insensitive OS, such as MacOS

@guyharris guyharris changed the title VERSION file causes an error while compilation on macOS VERSION file causes an error when building software that includes <version> and searches libpcap source directory for headers with a case-insensitive file system Jul 7, 2024
@guyharris
Copy link
Member

This is not a problem when trying to build libpcap.

It's a problem when trying to build other software that has #include <version> and that, for some reason, heppens to have the libpcap source directory in the include path.

Is there some reason why whatever software you're trying to build has the libpcap source directory in its include path?

@guyharris
Copy link
Member

nmap/nmap#2747

Nmap, for some unknown reason, has its own version of libpcap in its source code, and searches in the libpcap source directory for headers. That should be cleaned up by the Nmap developers.

@guyharris
Copy link
Member

https://groups.google.com/g/tesseract-ocr/c/MpCZe5wRYQE

For some unknown reason, the build process is looking for header files in the top-level source directory. They need to fix it not to do so.

@KrawMire
Copy link
Author

KrawMire commented Jul 7, 2024

Honestly, I am new to C++ and currently I and trying to learn it. I am really sorry for some misunderstanding. But I followed other developers' "best practices" and saw that they often include sources of external libraries into their own projects. How can you suggest to add a library to a project?

@guyharris
Copy link
Member

In what fashion does your project use libpcap?

If it just compiles and links with libpcap, there's no reason to include the entire libpcap project source into your own project - you don't need libpcap source for your project, you just need to have libpcap's include file and libraries available.

@KrawMire
Copy link
Author

KrawMire commented Jul 7, 2024

I have created git submodule inside my repository to copy all of libpcap source files. Thank you for your advice, I will try it!

@gvanem
Copy link
Contributor

gvanem commented Jul 8, 2024

@KrawMire

I suppose this error only happens on MacOS.

On Windows too. I reported the same issue back in 2021.

@KrawMire
Copy link
Author

KrawMire commented Jul 8, 2024

@gvanem oh, really, didn't notice your issue, sorry. As I see, there is no updates related to it, right?

@guyharris
Copy link
Member

As that issue says:

The complication seems to be caused by providing the full libpcap source tree to a 3rd-party build process.

I suggested restructuring the source directory for libpcap to put all include files in a separate directory, so that those who, for whatever reason, insist on pointing their source tree at a libpcap source tree rather than installed headers, can do so without being at risk of picking up files that aren't public headers.

That's not going to happen in a 1.10.x release, however.

@infrastation
Copy link
Member

In most use cases the best practice is to link, either dynamically or statically, with libpcap, but not to depend on libpcap source other than the public headers. If the build dependency is correctly satisfied this way, the VERSION and similar files are not present.

In less common use cases that genuinely demand a full copy of libpcap source (with or without modifications) the expectation is that the project developers know very well what they are doing and arrange the include paths in a way that does not trigger side effects on case-insensitive file systems.

This way, the current behaviour sometimes serves as an indicator that a project that uses libpcap may be not structured correctly, so keeping the tree source could the way it is now seems a sound alternative to restructuring.

@guyharris
Copy link
Member

In less common use cases that genuinely demand a full copy of libpcap source (with or without modifications) the expectation is that the project developers know very well what they are doing and arrange the include paths in a way that does not trigger side effects on case-insensitive file systems.

The first project that should fix this is a project called "tcpdump". :-)

If you're building against an installed libpcap, no problem, but if you're building against a libpcap downloaded into a directory at the same level as the tcpdump directory, it tries searching in the libpcap source directory before searching in system source directories (so that it gets the downloaded-and-built libpcap rather than the system libpcap).

Fortunately, it's not written in C++ and doesn't include anything that tries including <version>, so it doesn't have a problem, but if we want tell uses to arrange the include paths in that fashion, we should figure out how to allow a program to build against a private libpcap build directory without getting the wrong <version>.

@mcr
Copy link
Member

mcr commented Jul 23, 2024 via email

@guyharris
Copy link
Member

It seems to me that #include (no .h) is the part that's broken.

The ".h" in header file names is a convention, rather than an absolute requirement. In C code, header files all seem to be given .h names; for some reason, some header files for C++ aren't given extensions, and LLVM's libcpp, which Apple's SDKs use as the C++ library, has a header file named just "version".

@infrastation
Copy link
Member

#1043 is an earlier discussion of the same problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

5 participants