BitNet icon indicating copy to clipboard operation
BitNet copied to clipboard

solve the errors building llama.cpp

Open Mezca1 opened this issue 3 months ago • 8 comments

when cmd shows that

python setup_env.py -md models/BitNet-b1.58-2B-4T -q i2_s INFO:root:Compiling the code using CMake. ERROR:root:Error occurred while running command: Command '['cmake', '--build', 'build', '--config', 'Release']' returned non-zero exit status 1., check details in logs\compile.log

you can add #include in \BitNet\3rdparty\llama.cpp\common\common.cpp

Mezca1 avatar Sep 13 '25 14:09 Mezca1

Can you show logs\compile.log file here ?

ArrivedAditya avatar Sep 21 '25 12:09 ArrivedAditya

Had the same problem, used Mingw instead of visual studio, check this out and let me know if it helps. https://github.com/saifxyzyz/Bitnet-Mingw.git

saifxyzyz avatar Sep 25 '25 21:09 saifxyzyz

Had the same problem, used Mingw instead of visual studio, check this out and let me know if it helps. https://github.com/saifxyzyz/Bitnet-Mingw.git

Nope it doesn't helps. It just straight fork but without changes.

ArrivedAditya avatar Sep 28 '25 14:09 ArrivedAditya

The only fatal error in the log is: common.cpp(445,32): error : no type named 'system_clock' in namespace 'std::chrono' common.cpp(447,11): error : 'clock' is not a class, namespace, or enumeration

Root Cause common.cpp uses std::chrono::system_clock (C++11) but the translation unit does not contain #include , so clang-cl on Windows cannot find the definition.

Impact Only llama-common.lib fails to build; all subsequent executables (including run_inference) cannot link, so the entire BitNet pipeline is blocked.

One-Click Fix (pick either) Method 1: Add the missing header locally (fastest, no upstream wait) Open ~\BitNet\3rdparty\llama.cpp\common\common.cpp add: #include

by kimi k2

Mezca1 avatar Sep 28 '25 15:09 Mezca1

Root Cause common.cpp uses std::chrono::system_clock (C++11) but the translation unit does not contain #include , so clang-cl on Windows cannot find the definition.

Impact Only llama-common.lib fails to build; all subsequent executables (including run_inference) cannot link, so the entire BitNet pipeline is blocked.

If that so it should be failed build by all platform then. Problem should be that windows is handling clang natively different than other platforms. But using wsl this issue is not happening.

So, the easiest solution is to use wsl for building and running it.

By the way I run it on wsl in windows 10. Because setting clang in windows is quite headache for me.

ArrivedAditya avatar Sep 29 '25 08:09 ArrivedAditya

I added #include , but it does not work. Same error:

ERROR:root:Error occurred while running command: Command '['cmake', '--build', 'build', '--config', 'Release']' returned non-zero exit status 1., check details in logs\compile.log.

I get several warnings and the following error: ...\BitNet\3rdparty\llama.cpp\common\log.cpp(28,79): error : no member named 'system_clock' in namespace 'std::chrono' [...\BitNet\build\3rdparty\llama.cpp\common\common.vcxproj]

GMP2475 avatar Oct 02 '25 15:10 GMP2475

Just completed to compile. I solved adding in CMakeLists.txt: set(CMAKE_CXX_STANDARD 17) # this one set(CMAKE_CXX_STANDARD_REQUIRED true)

and various #include. in servela files as indicated by the logs\compile.log

GMP2475 avatar Oct 02 '25 16:10 GMP2475

https://github.com/tinglou/llama.cpp/commit/4e3db1e3d78cc1bcd22bcb3af54bd2a4628dd323

To fix build error do this

🧩 Fix: setup_env.py Compilation Error

If you face errors related to missing <chrono>, you need to modify the following files in the llama.cpp dependency.

Reference Commit:
https://github.com/tinglou/llama.cpp/commit/4e3db1e3d78cc1bcd22bcb3af54bd2a4628dd323

Add this line to each affected file:

#include <chrono>

✅ Modified Files

1. 3rdparty\llama.cpp\examples\imatrix\imatrix.cpp

Location: Line 6 (after existing includes)

Before:

#include "arg.h"
#include "common.h"
#include "log.h"
#include "llama.h"

#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <sstream>
#include <thread>
#include <mutex>
#include <vector>
#include <fstream>
#include <unordered_map>
#include <algorithm>

After:

#include "arg.h"
#include "common.h"
#include "log.h"
#include "llama.h"

#include <chrono>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <sstream>
#include <thread>
#include <mutex>
#include <vector>
#include <fstream>
#include <unordered_map>
#include <algorithm>

2. 3rdparty\llama.cpp\examples\perplexity\perplexity.cpp

Location: Line 9 (after existing includes)

Before:

#include "arg.h"
#include "common.h"
#include "log.h"
#include "llama.h"

#include <algorithm>
#include <array>
#include <atomic>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <fstream>
#include <mutex>
#include <random>
#include <sstream>
#include <thread>
#include <vector>

After:

#include "arg.h"
#include "common.h"
#include "log.h"
#include "llama.h"

#include <algorithm>
#include <array>
#include <atomic>
#include <chrono>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <fstream>
#include <mutex>
#include <random>
#include <sstream>
#include <thread>
#include <vector>

3. common/log.cpp

#include "log.h"

#include <chrono>
#include <condition_variable>
#include <cstdarg>
#include <cstdio>

4. common/common.cpp

#include "log.h"

#include <chrono>
#include <condition_variable>
#include <cstdarg>
#include <cstdio>

farman-mk avatar Oct 08 '25 06:10 farman-mk