Saltar al contenido principal
ProductosHerramientas de escritorioTASTECADRevisión de planosTASTEFILESGestión de archivosTASTEFTPTransferencia de archivosTASTESSHEspacio de trabajo remotoTASTEZIPCompresión y extracciónTASTEWINMGestión de archivosHerramientas para desarrolladoresTASTECODEEntorno de desarrollo integrado para RustTASTESTUDIOEntorno integrado de desarrollo y pruebasTASTEETLIntegración de datos (ETL)ServidoresTASTEREMOTEServidor de escritorio remotoTASTEGEOServidor geoespacialTASTEMAILEspacio de trabajo de correoInversiónTASTESTOCKAplicación de escritorio de trading automático de accionesEmpezarDescargasDocumentaciónComprarTodos los productos
Marketplace
Noticias
TecnologíaNoticiasNoticias de desarrollo de hoyDocumentaciónLenguajes de programaciónRustTypeScriptJavaScriptPythonGoC#JavaCC++KotlinDartFrameworks web frontendNext.jsReactVue.js · NuxtSvelteKitAngularFrameworks de servidorSpring BootDjangoFastAPIASP.NET CoreNestJS · ExpressFrameworks de apps y escritorioTauriFlutterReact NativeElectronAlgoritmosFundamentos de algoritmosAlgoritmos esencialesAlgoritmos avanzadosAlgoritmos prácticos
ComunidadProyectosRegistros de desarrolloPromptsProblemas con herramientas de IAEscaparateGuía de la comunidad
ColaboraTransferencia técnicaDesarrollo de sitio webDesarrollo de app de escritorioCanal de lanzamiento y pagosSocio de ventasContacto
ServiciosEscritorio remotoPaquetes de instalación a medida
TASTEDEV
Productos

Herramientas de escritorio

TASTECADAbre planos complejos con ligerezaTASTEFILESSolo los archivos que necesitas, lo más rápido posibleTASTEFTPEl camino más limpio para tus archivosTASTESSHEntre tu servidor y tú, una conexión más sólidaTASTEZIPComprime más rápido, descomprime más seguroTASTEWINMUn gestor de archivos de dos paneles pensado para el teclado

Herramientas para desarrolladores

TASTECODEEdita, compila, depura y prueba apps de Rust en una sola ventanaTASTESTUDIODe la edición a las pruebas remotas y las correcciones con IA aprobadasTASTEETLMueve datos viendo sus valores

Servidores

TASTEREMOTEUn escritorio remoto que funciona en tu propio servidorTASTEGEOUn servidor geoespacial compatible con GeoServer, reconstruido en RustTASTEMAILRecupera el control de tu correo

Inversión

TASTESTOCKTrading automático de acciones según las reglas que tú defines: cuándo y qué

Empezar

DescargasÚltimas versiones de cada productoDocsCómo usar cada productoComprarSuscripciones y licencias perpetuasTodos los productosTodos los productos de un vistazo
Todos los productos
MarketplaceNoticias
Tecnología

Noticias

Noticias de desarrollo de hoyAnuncios oficiales de lenguajes, frameworks, GitHub e IADocumentaciónGuías de lenguajes, frameworks y algoritmos

Lenguajes de programación

RustTypeScriptJavaScriptPythonGoC#JavaCC++KotlinDart

Frameworks

Frameworks web frontendNext.jsReactVue.js · NuxtSvelteKitAngular
Frameworks de servidorSpring BootDjangoFastAPIASP.NET CoreNestJS · Express
Frameworks de apps y escritorioTauriFlutterReact NativeElectron

Algoritmos

Fundamentos de algoritmosAnálisis de complejidad · Ordenamiento · Búsqueda · Estructuras de datos básicas · Árboles y montículosAlgoritmos esencialesRecorrido de grafos · Camino mínimo y árbol generador mínimo · Programación dinámica · Algoritmos voraces · Divide y vencerás · Backtracking (vuelta atrás)Algoritmos avanzadosAlgoritmos de cadenas · Matemáticas y teoría de números · Manipulación de bits · Árboles de segmentos · Union-FindAlgoritmos prácticosEstrategia para entrevistas de código · Caché LRU · Limitación de tasa · Hashing consistente
Toda la documentación de desarrollo
Comunidad
ProyectosDescubre creadores y su trabajoRegistros de desarrolloDecisiones y aprendizajesPromptsInstrucciones reutilizablesProblemas con herramientas de IAProblemas y alternativas de Claude, Codex, GeminiEscaparateResultados terminadosGuía de la comunidadCómo construimos en abierto
Colabora
Transferencia técnicaApps nativas con Rust y eguiDesarrollo de sitio web10 idiomas, cuentas, documentación y descargasDesarrollo de app de escritorioRust y egui, sin WebViewCanal de lanzamiento y pagosFirma, MSI, deb, rpm, AppImage, hashesSocio de ventasRecomiéndanos y gana el 30 %ContactoDesarrollo, alianzas e inversión
Servicios
Escritorio remotoAccede a tu ordenador desde el navegadorPaquetes de instalación a medidaSolo lo necesario, ajustes precargados
Comprar
ES
한국어EnglishDeutschEspañolFrançaisItalianoPortuguês (Brasil)日本語简体中文繁體中文
Iniciar sesión
Iniciar sesión
TASTEDEV

De pequeñas herramientas a un mejor desarrollo.

support@tastedev.netApoyar a TASTEDEV
ProductosLínea de productosComprarDocsDescargasMarketplaceSoporte
ComunidadProyectosRegistros de desarrolloPromptsProblemas con herramientas de IAEscaparate
PolíticasQuiénes somosPolítica de privacidadTérminos de servicioCondiciones de suscripciónReembolsosNormas de la comunidad
CuentaIniciar sesiónRegistrarse
Visitantes
Hoy
Ayer
Vistas totales
Empresa
GXSOFT
Representante
CHOI YOUNG GU
Número de registro mercantil
853-44-00368
Dirección
9F V24, 351 Gyeongin-ro, Michuhol-gu, Incheon, Republic of Korea
Teléfono
+82-10-4404-1523
Correo electrónico
whitecalvin@tastedev.net
Responsable de privacidad
CHOI YOUNG GU

© 2026 TASTEDEVLa información de los productos se basa en fuentes de desarrollo verificadas.Publicado · en mejora

Documentación de C
C
Getting StartedSyntax BasicsTypes and DataModules and LibrariesErrors and TestingKey Concepts: Pointers and Memory
Debates

Guía de C · 4/6

Modules and Libraries

Por ahora, este capítulo solo está disponible en inglés.

C has no module system or package manager built into the language. Instead, you split a program into header files (.h) holding declarations and source files (.c) holding implementations, compile each source file separately, and let the linker stitch the results together. This chapter covers that split, separate compilation, static and shared libraries, and the basics of Make and CMake.

Splitting headers and sources

A header contains only what other files need to know: prototypes, type definitions, and constants. Function bodies live in the source file. An include guard keeps the header harmless if it ends up included twice in the same translation unit.

// mathutil.h
#ifndef MATHUTIL_H
#define MATHUTIL_H

#include <stddef.h>

typedef struct {
    double min, max, mean;
} Stats;

int clamp(int value, int lo, int hi);
Stats compute_stats(const double *values, size_t count);

#endif // MATHUTIL_H
// mathutil.c
#include "mathutil.h"

static double sum(const double *values, size_t count) {   // private to this file
    double total = 0.0;
    for (size_t i = 0; i < count; i++) total += values[i];
    return total;
}

int clamp(int value, int lo, int hi) {
    if (value < lo) return lo;
    if (value > hi) return hi;
    return value;
}

Stats compute_stats(const double *values, size_t count) {
    Stats s = { values[0], values[0], 0.0 };   // assumes count >= 1
    for (size_t i = 1; i < count; i++) {
        if (values[i] < s.min) s.min = values[i];
        if (values[i] > s.max) s.max = values[i];
    }
    s.mean = sum(values, count) / (double)count;
    return s;
}
// main.c
#include <stdio.h>
#include "mathutil.h"

int main(void) {
    double data[] = {3.0, 9.5, 1.5, 6.0};
    Stats s = compute_stats(data, sizeof data / sizeof data[0]);
    printf("min %.1f, max %.1f, mean %.2f\n", s.min, s.max, s.mean);
    printf("clamp: %d\n", clamp(120, 0, 100));
    return 0;
}

A few rules of thumb:

  • Use #include <...> for system headers and #include "..." for your own.
  • Marking a function static gives it internal linkage, so nothing outside the file can see it. Hide anything that is not part of the public interface.
  • To share a global variable, declare it in the header as extern int counter; and define it as int counter = 0; in exactly one source file.
  • #pragma once is not standard C, but every major compiler supports it as an alternative to include guards.

Separate compilation and linking

Compile each source file to an object file with -c, then link the objects. When you edit one file, only that file needs recompiling.

gcc -std=c17 -Wall -Wextra -c mathutil.c -o mathutil.o
gcc -std=c17 -Wall -Wextra -c main.c -o main.o
gcc main.o mathutil.o -o stats
./stats
¿Tienes preguntas sobre este capítulo?
Capítulo anteriorTypes and DataCapítulo siguienteErrors and Testing

Leave mathutil.o out of the link step and you get an error like "undefined reference to compute_stats". Compilation succeeded because the header declared the function, but the linker could not find a definition. The opposite mistake, defining the same function in two source files, produces a "multiple definition" error.

Static and shared libraries

Bundling object files into a library makes them easy to reuse across programs.

KindLinuxmacOSWindowsBehavior
Static.a.a.libCopied into the executable at link time
Shared.so.dylib.dllLoaded at run time and shared between programs
# static library
ar rcs libmathutil.a mathutil.o
gcc main.o -L. -lmathutil -o stats_static

# shared library (Linux)
gcc -fPIC -c mathutil.c -o mathutil.pic.o
gcc -shared mathutil.pic.o -o libmathutil.so
gcc main.o -L. -lmathutil -Wl,-rpath,'$ORIGIN' -o stats_shared

-L adds a directory to the library search path, and -lmathutil means libmathutil.a or libmathutil.so. The GNU linker resolves symbols left to right, so list libraries after the object files that use them. A shared library also has to be found when the program runs, so either embed an rpath as above or install it to a standard library directory.

Make and CMake

Once a project has more than a handful of files, let a build tool run the commands. Make describes rules as "target: prerequisites" followed by a recipe, and rebuilds only what is out of date. Recipe lines must be indented with a tab character, not spaces.

CC      = gcc
CFLAGS  = -std=c17 -Wall -Wextra -g
OBJS    = main.o mathutil.o

stats: $(OBJS)
	$(CC) $(OBJS) -o $@

%.o: %.c mathutil.h
	$(CC) $(CFLAGS) -c $< -o $@

clean:
	rm -f stats $(OBJS)

.PHONY: clean

$@ expands to the target and $< to the first prerequisite. Run make to build and make clean to remove the outputs.

CMake works one level higher: it generates build files for Make, Ninja, Visual Studio, and others, and it hides compiler-specific flags. That makes it the common choice for projects that build on several platforms.

cmake_minimum_required(VERSION 3.16)
project(stats C)

set(CMAKE_C_STANDARD 17)
set(CMAKE_C_STANDARD_REQUIRED ON)

add_library(mathutil STATIC mathutil.c)
target_include_directories(mathutil PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})

add_executable(stats main.c)
target_link_libraries(stats PRIVATE mathutil)
cmake -S . -B build
cmake --build build
./build/stats

Change STATIC to SHARED in add_library to produce a shared library instead. All outputs land in the separate build directory, which keeps the source tree clean.

Summary

  • Declarations go in headers, definitions in sources, and every header gets an include guard.
  • Use static to keep non-public functions and globals private to their file.
  • Compile each file with -c and link at the end; "undefined reference" is a link-time error.
  • Static libraries are copied into the executable; shared libraries are loaded at run time.
  • Make suits small projects; CMake is the usual choice for cross-platform builds.

0 comentarios

Comentarios destacadosMás recientes primero

Iniciar sesión · Inicia sesión para dejar un comentario.