Skip to content
New issue

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

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

Already on GitHub? # to your account

included string.h but still see "implicitly declaring library function 'memcpy'" #512

Closed
randy3k opened this issue Oct 23, 2019 · 5 comments

Comments

@randy3k
Copy link

randy3k commented Oct 23, 2019

I am using Sublime Text LSP in macOS.

The c file

#include <string.h>

// something else

void utf8_to_utf32_callback(int cp, int m, void* data, long i) {
    uint32_t x = cp;
    memcpy((char*) data + sizeof(uint32_t) * i, &x, sizeof(uint32_t));
}

Diagnostic

      104:5   	ccls        	warning   	implicitly declaring library function 'memcpy' with type 'void *(void *, const void *, unsigned long)'
             	            	          	
             	            	          	utftools.c:104:5: note: include the header <string.h> or explicitly provide a declaration for 'memcpy'
      104:5   	ccls        	info      	include the header <string.h> or explicitly provide a declaration for 'memcpy'

When I check the ccls log file, I could see string.h is indexed.

10:01:30                  pipeline.cc:389 I store index for /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/string.h (delta: 0)

But having a closer look of the string.h, it doesn't contain the definiation of memcpy but the following derivative

#include_next <string.h>

Does it mean that ccls is not following the #include_next derivative? I cannot see other string.h file being indexed except /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/string.h.

Please let me know if you need more information.

  • ccls installed freshly from homebrew.
  • the file could be compiled without problems.
@randy3k
Copy link
Author

randy3k commented Oct 23, 2019

Ok. I found a solution, I think it may affect other macOS users with more recent OSs.
Bascially, standard headers are no longer located at /usr/include they are located at

/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include

or

/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include

So I fix the issue by adding -isysroot/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include in clang.extraArgs.

Not only that, but I also need the fix in #191 (comment)

@randy3k randy3k closed this as completed Oct 23, 2019
@zero4drift
Copy link

@randy3k Your solution here helps me a lot, Thank you! I've been struggling on Catalina 15.2 for nearly two days!

@MaskRay
Copy link
Owner

MaskRay commented Dec 28, 2019

Does https://github.com/MaskRay/ccls/wiki/Build#macos include all the information now? (It is publicly editable BTW)

@zero4drift
Copy link

@MaskRay I suppose it's a MacOS Catalina only problem, I've updated the wiki page you posted with a tip, hoping it could help somebody in the future.

@apple-ihack-geek
Copy link

For those whom run into this error and find this page via google,
I had the same issue with Xcode 11.0 running on 10.4.6. I'm guessing the error was the opposite of what these users ran into. I'm guessing my Xcode was looking in the Catalina location and not the old Mojave location. I was able to resolve my issue by simply updating my Xcode to 11.3.
Best of luck to all of you and that's to the original answerers for giving me the idea to update.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants