1) Why install GCC when you code Golang?
Nếu bạn sử dụng package: https://github.com/confluentinc/confluent-kafka-go
Mình chắc chắn các bạn sẽ cần cài gcc
Ủa. Teo đang code Golang mà bay cài GCC chi?
When using confluent-kafka-go
, a Go client for Apache Kafka developed by Confluent, it’s often necessary to install GCC (GNU Compiler Collection). This requirement arises due to the following reasons:
- CGo Dependency:
confluent-kafka-go
relies on CGo to interface with the librdkafka C library. CGo is a feature in Go that allows for the creation of Go packages that call C code. Since GCC is a C compiler, it’s needed to compile this C code into a format that the Go runtime can interface with. - librdkafka: This is a C library implementation of the Apache Kafka protocol, which provides Producer, Consumer, and Admin clients.
confluent-kafka-go
is a wrapper around this library. Therefore, to useconfluent-kafka-go
, you need to have librdkafka installed and compiled on your system, which requires a C compiler like GCC. - Performance and Integration: Using native libraries like librdkafka can offer better performance and more features compared to pure Go implementations. This integration, however, comes at the cost of additional complexity in the build process, including the need for a C compiler.
- Cross-Language Support: The reliance on librdkafka means that
confluent-kafka-go
can take advantage of developments and optimizations in the Kafka ecosystem that are made in C, ensuring compatibility and performance across different languages that also use librdkafka. - System Dependencies: Besides GCC, you may also need to install other dependencies related to the development environment for C, such as
libssl-dev
andlibsasl2-dev
for secure communication and authentication with Kafka brokers.
Đọc hết các điều trên thì bạn đã cảm thấy thông não chưa?
Ok vậy làm sao cài GCC.
2) Install GCC Compiler On Windows OS
Trên windows bạn cần cài 2 cài này:
Install Gitbash: https://git-scm.com/download/win
Install Msys2: https://www.msys2.org/
Tiếp đến bạn sẽ thấy nó xuất hiện 1 console.
Bạn điền vào mingw-w64 GCC
pacman -S mingw-w64-ucrt-x86_64-gcc
Tiếp đến là: Mingw-w64 toolchain
pacman -S --needed base-devel mingw-w64-x86_64-toolchain
Bạn gõ tiếp gcc –version
Giờ bạn cần add nó vào path của environment windows.
Khi này bạn gõ gcc trong cmd sẽ report là OK
Configure GCC for Goland.
Bạn sẽ thực hiện edit configuration của project
Xong bạn add nó vào env