0

所以我正在尝试运行一些在 Windows 中完美编译的 c 代码,并尝试使用 Xcode 和 gcc 编译器运行相同的代码,当我尝试编译时,我的代码中出现此错误

架构 x86_64 的未定义符号:“_stricmp”,引用自:cckZHFWV.o 中的 _PrintResults ld:未找到架构 x86_64 的符号 collect2:ld 返回 1 个退出状态

并且无法弄清楚为什么我会收到此错误

这是我要编译的代码

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include "definitions.h"

//#define DEBUG 1

int main(int argc, char *argv[]) {
    FILE *config_file, *trace;
    unsigned int address, exec_info;
    char check, trash[25], op;
    int j, para;
    int i=0;

    //    char valid,dirty;
    //    unsigned int tag;
    //    next *tagstr;
    //    bptr tptr
    //    check if tptr is at head of list dont use bptr, dummy pointer

    if(argc >= 2)   
    config_file = fopen(argv[1],"r");    
    else 
    config_file = fopen("config0.txt","r");

    // Grabs desired cache parameters from the specified config files
    while(fscanf(config_file,"%s %d\n",trash,&para) == 2) {
    config[i] = para;
   i++;      
    }

    // Close the config file
    fclose(config_file);

    // Puts Cache parameters from config file in desired variables
    InitializeParameters();

    // Initializes the L1 and L2 caches into Linked List
    CacheInit();

    // Checks to see if file exists
    trace = fopen("I10.txt","r");
    if (!trace) {
    puts("I1.txt not found!");
    return 1;
    }

    while (fscanf(trace,"%c %x %x\n",&op,&address,&exec_info) == 3) {
    //printf("Op is %c, Address is %x, and exec is %x\n",op,address,exec_info); 
    switch(op) {
    case 'L': {
        load_count++;
        total++;
        //printf("Welcome to Load.\n");
        // do something
    }
    break;      
    case 'S': {
        store_count++;
        total++;
        //printf("Welcome to Store.\n");
        // do something here also
    }
    break;
    case 'B': {
        branch_count++;
        total++;
        //printf("Welcome to Branch.\n");
        // oh, don't forget this
    }
    break;      
    case 'C': {
        comp_count++;
        total++;
        //printf("Welcome to Computation.\n");        
        // Here, too 
    }
    break;
    }   // Handles incoming Operation data   
    }

    // Prints the Results of the Simulation
    PrintResults(argv[1]);
}

int InitializeParameters() {   
    L1_cache_size = config[0];
    L1_block_size = config[1];
    L1_assoc = config[2];
    L1_hit_time = config[3];
    L1_miss_time = config[4];
    L2_block_size = config[5];
    L2_cache_size = config[6];
    L2_assoc = config[7];
    L2_hit_time = config[8];
    L2_miss_time = config[9];
    L2_transfer_time = config[10];
    L2_bus_width = config[11];
    mem_sendaddr=config[12];
    mem_ready=config[13];
    mem_chunktime=config[14];
    mem_chunksize=config[15];    
}

int CacheInit() {
if(L1_assoc == 0){
L1_assoc = L1_cache_size / L1_block_size;
L1_sets = 1;
}
else
L1_sets = L1_cache_size / L1_block_size / L1_assoc;

if(L2_assoc == 0){
L2_assoc = L2_cache_size / L2_block_size;
L2_sets = 1;
}
else
L2_sets = L2_cache_size / L2_block_size / L2_assoc;    
}

int PrintResults(char *config_file) {
printf("--------------------------------------------------------\n");
printf("                   Simulation Results\n");
printf("--------------------------------------------------------\n");

// Trace File
printf("Trace File:\n");

// Cache Name
printf("Cache Type: ");
if (config_file == NULL)
printf("Direct Mapped\n\n");
if (stricmp("config0.txt",config_file) == 0)
printf("Direct Mapped\n\n");
if (stricmp("config1.txt",config_file) == 0)
printf("L1-2way\n\n");
if (stricmp("config2.txt",config_file) == 0)
printf("L2-2way\n\n");
if (stricmp("config3.txt",config_file) == 0)
printf("All-2way\n\n");
if (stricmp("config4.txt",config_file) == 0)
printf("2-4-way\n\n");
if (stricmp("config5.txt",config_file) == 0)
printf("L2-Big\n\n");
if (stricmp("config6.txt",config_file) == 0)
printf("All-FA\n\n");
if (stricmp("config7.txt",config_file) == 0)
printf("Direct Mapped 2 x Memory Chunksize\n\n");
if (stricmp("config8.txt",config_file) == 0)
printf("Direct Mapped 4 x Memory Chunksize%s\n\n");     

// Cache info
printf("Memory System:\n");
printf("  DCache Size = %Lu : Ways = %Lu : Block Size = %Lu\n",
   L1_cache_size, L1_assoc, L1_block_size);
printf("  ICache Size = %Lu : Ways = %Lu : Block Size = %lu\n",
   L1_cache_size, L1_assoc, L1_block_size);
printf("  L2-Cache Size = %Lu : Ways = %Lu : Block Size = %lu\n",
   L2_cache_size, L2_assoc, L2_block_size);
printf("  Memory Ready Time = %Lu : Chunksize = %Lu : Chunktime = %lu\n\n", mem_ready, mem_chunksize, mem_chunktime);

// Time
printf("Time:\n");
printf("  Execute Time = %Lu :", time);
printf(" Total Refs = %Lu\n", total + data_refs);
printf("  Inst Refs = %Lu :", total);
printf(" Data Refs = %Lu\n\n", data_refs);

// Number of Instructions
printf("Number of Instructions: [Percentage]\n");
printf("  Loads  (L) = %Lu",load_count);
printf(" [%.1f%%] :",100*load_count/ (double) total);
printf(" Stores (S) = %Lu",store_count);
printf(" [%.1f%%]\n",100*store_count/ (double) total);
printf("  Branch (B) = %Lu",branch_count);
printf(" [%.1f%%] :",100*branch_count/ (double) total);
printf(" Comp   (C) = %Lu",comp_count);
printf(" [%.1f%%]\n",100*comp_count/ (double) total);
printf("  Total  (T) = %Lu\n\n",total);

// Number of Cycles
printf("Cycles for Instructions: [Percentage]\n");
printf("  Loads  (L) = %Lu",load_cycle);
printf(" [%.1f%%] :",100*load_cycle/ (double) total_cycle);
printf(" Stores (S) = %Lu",store_cycle);
printf(" [%.1f%%]\n",100*store_cycle/ (double) total_cycle);
printf("  Branch (B) = %Lu",branch_cycle);
printf(" [%.1f%%] :",100*branch_cycle/ (double) total_cycle);
printf(" Comp   (C) = %Lu",comp_cycle);
printf(" [%.1f%%]\n",100*comp_cycle/ (double) total_cycle);
printf("  Total  (T) = %Lu\n\n",total_cycle);

// CPI
printf("Cycles Per Instructions:\n");
printf("  Loads      (L) = %.1f :", load_cycle/(double) load_count);
printf("  Stores (S) = %.1f%\n", store_cycle/(double) store_count);
printf("  Branch     (B) = %.1f :",
   branch_cycle/(double) branch_count);
printf("  Comp   (C) = %.1f\n", comp_cycle/ (double) comp_count);
printf("  Overall  (CPI) = %Lu\n\n", total_cycle/ (double) total);

// Real/Simulated Comparision
printf("Perfect to Simulation Comparision:\n");
printf("  Cycles for Processor w/Perfect Memory System %Lu\n",
   perfect_cycle);
printf("  Cycles for Processor w/Simulated Memory System %Lu\n",
   total_cycle);
printf("  Ratio of Simulated/Perfect Performance = %.6f\n\n",
   total_cycle/ (double) perfect_cycle );

// L1 ICache Hit/Miss
printf("Memory Level: L1 ICache\n");
printf("  Hit Count = %Lu : ", L1_I_hits);
printf("Miss Count = %Lu : ", L1_I_misses);
printf("Hit Count = %Lu\n", L1_I_hits+L1_I_misses);
printf("  Hit Rate = %.1f%% : Miss Rate = %.1f%%\n",
   100*L1_I_hits / (double) (L1_I_hits + L1_I_misses),
   100*L1_I_misses / (double) (L1_I_hits + L1_I_misses));
printf("  Kickouts = %Lu : ", L1_I_kickouts);
printf("Dirty Kickouts = %Lu : ", L1_I_kickouts_dirty);
printf("Transfers = %Lu\n\n", L1_I_transfers);

// L1 DCache Hit/Miss
printf("Memory Level: L1 DCache\n");
printf("  Hit Count = %Lu : ", L1_D_hits);
printf("Miss Count = %Lu : ", L1_D_misses);
printf("Hit Count = %Lu\n", L1_D_hits+L1_D_misses);
printf("  Hit Rate = %.1f%% : Miss Rate = %.1f%%\n",
   100*L1_D_hits / (double) (L1_D_hits + L1_D_misses),
   100*L1_D_misses / (double) (L1_D_hits + L1_D_misses));
printf("  Kickouts = %Lu : ", L1_D_kickouts);
printf("Dirty Kickouts = %Lu : ", L1_D_kickouts_dirty);
printf("Transfers = %Lu\n\n", L1_D_transfers);

// L2 Cache Hit/Miss
printf("Memory Level: L2\n");
printf("  Hit Count = %Lu : ", L2_hits);
printf("Miss Count = %Lu : ", L2_misses);
printf("Hit Count = %Lu\n", L2_hits+L2_misses);
printf("  Hit Rate = %.1f%% : Miss Rate = %.1f%%\n",
   100*L2_hits / (double) (L2_hits + L1_D_misses),
   100*L2_misses / (double) (L2_hits + L2_misses));
printf("  Kickouts = %Lu : ", L2_kickouts);
printf("Dirty Kickouts = %Lu : ", L2_kickouts_dirty);
printf("Transfers = %Lu\n\n", L2_transfers);

// Cost Analysis
printf("Cost:\n");
//L1 Cache Cost
L1_cost = (L1_cache_size / 4096) * 100 * (log2(L1_assoc) + 1);
cost += L1_cost*2;
printf("  L1 Cache Cost (ICache $%Lu) + (DCache $%Lu) = $%Lu\n",
   L1_cost, L1_cost, L1_cost*2);

// L2 Cache Cost
L2_cost = (L2_cache_size / (64*1024)) * 50 * (log2(L2_assoc) + 1);
cost += L2_cost;
printf("  L2 Cache Cost = $%Lu\n", L2_cost);

// Memory Cost
mem_cost = log2(100 / mem_ready) * 200 + 50;
mem_cost += (log2(mem_chunksize)-4)*100 + 25;
cost += mem_cost;
printf("  Memory Cost = $%Lu\n", mem_cost);

// Total Cost
printf("  Total Cost = $%Lu\n", cost);
}

谢谢你的帮助

4

1 回答 1

4

stricmp不是标准库函数,也不是可移植的。 strcasecmp是便携功能。

于 2012-04-25T22:59:00.713 回答